use of org.springframework.core.ResolvableType in project spring-framework by spring-projects.
the class Jackson2JsonEncoderTests method encode.
@Test
public void encode() 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, null, Collections.emptyMap());
StepVerifier.create(output).consumeNextWith(stringConsumer("[{\"foo\":\"foo\",\"bar\":\"bar\"},{\"foo\":\"foofoo\",\"bar\":\"barbar\"},{\"foo\":\"foofoofoo\",\"bar\":\"barbarbar\"}]")).expectComplete().verify();
}
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-boot by spring-projects.
the class JsonComponentModule method addDeserializerWithDeducedType.
@SuppressWarnings({ "unchecked" })
private <T> void addDeserializerWithDeducedType(JsonDeserializer<T> deserializer) {
ResolvableType type = ResolvableType.forClass(JsonDeserializer.class, deserializer.getClass());
addDeserializer((Class<T>) type.resolveGeneric(), deserializer);
}
Aggregations