use of org.springframework.core.ResolvableType in project spring-framework by spring-projects.
the class Jackson2JsonEncoderTests method canEncode.
@Test
public void canEncode() {
ResolvableType pojoType = ResolvableType.forClass(Pojo.class);
assertTrue(this.encoder.canEncode(pojoType, MediaType.APPLICATION_JSON));
assertTrue(this.encoder.canEncode(pojoType, null));
assertFalse(this.encoder.canEncode(pojoType, MediaType.APPLICATION_XML));
ResolvableType sseType = ResolvableType.forClass(ServerSentEvent.class);
assertFalse(this.encoder.canEncode(sseType, MediaType.APPLICATION_JSON));
}
use of org.springframework.core.ResolvableType in project spring-framework by spring-projects.
the class Jackson2JsonEncoderTests method encodeAsStream.
@Test
public void encodeAsStream() throws Exception {
Flux<Pojo> source = Flux.just(new Pojo("foo", "bar"), new Pojo("foofoo", "barbar"), new Pojo("foofoofoo", "barbarbar"));
ResolvableType type = ResolvableType.forClass(Pojo.class);
Flux<DataBuffer> output = this.encoder.encode(source, this.bufferFactory, type, APPLICATION_STREAM_JSON, Collections.emptyMap());
StepVerifier.create(output).consumeNextWith(stringConsumer("{\"foo\":\"foo\",\"bar\":\"bar\"}\n")).consumeNextWith(stringConsumer("{\"foo\":\"foofoo\",\"bar\":\"barbar\"}\n")).consumeNextWith(stringConsumer("{\"foo\":\"foofoofoo\",\"bar\":\"barbarbar\"}\n")).expectComplete().verify();
}
use of org.springframework.core.ResolvableType in project spring-framework by spring-projects.
the class Jackson2JsonEncoderTests method jsonView.
@Test
public void jsonView() throws Exception {
JacksonViewBean bean = new JacksonViewBean();
bean.setWithView1("with");
bean.setWithView2("with");
bean.setWithoutView("without");
ResolvableType type = ResolvableType.forClass(JacksonViewBean.class);
Map<String, Object> hints = Collections.singletonMap(Jackson2JsonEncoder.JSON_VIEW_HINT, MyJacksonView1.class);
Flux<DataBuffer> output = this.encoder.encode(Mono.just(bean), this.bufferFactory, type, null, hints);
StepVerifier.create(output).consumeNextWith(stringConsumer("{\"withView1\":\"with\"}")).expectComplete().verify();
}
use of org.springframework.core.ResolvableType in project spring-framework by spring-projects.
the class Jackson2JsonDecoderTests method canDecode.
@Test
public void canDecode() {
Jackson2JsonDecoder decoder = new Jackson2JsonDecoder();
ResolvableType type = ResolvableType.forClass(Pojo.class);
assertTrue(decoder.canDecode(type, MediaType.APPLICATION_JSON));
assertTrue(decoder.canDecode(type, null));
assertFalse(decoder.canDecode(type, MediaType.APPLICATION_XML));
}
use of org.springframework.core.ResolvableType in project spring-framework by spring-projects.
the class Jackson2JsonDecoderTests method jsonView.
@Test
public void jsonView() throws Exception {
Flux<DataBuffer> source = Flux.just(stringBuffer("{\"withView1\" : \"with\", \"withView2\" : \"with\", \"withoutView\" : \"without\"}"));
ResolvableType elementType = ResolvableType.forClass(JacksonViewBean.class);
Map<String, Object> hints = Collections.singletonMap(Jackson2JsonDecoder.JSON_VIEW_HINT, MyJacksonView1.class);
Flux<JacksonViewBean> flux = new Jackson2JsonDecoder().decode(source, elementType, null, hints).cast(JacksonViewBean.class);
StepVerifier.create(flux).consumeNextWith(b -> {
assertTrue(b.getWithView1().equals("with"));
assertNull(b.getWithView2());
assertNull(b.getWithoutView());
}).expectComplete().verify();
}
Aggregations