use of org.springframework.core.io.buffer.DataBuffer 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.io.buffer.DataBuffer in project spring-framework by spring-projects.
the class Jaxb2XmlDecoderTests method decodeSingleXmlRootElement.
@Test
public void decodeSingleXmlRootElement() throws Exception {
Flux<DataBuffer> source = Flux.just(stringBuffer(POJO_ROOT));
Flux<Object> output = this.decoder.decode(source, ResolvableType.forClass(Pojo.class), null, Collections.emptyMap());
StepVerifier.create(output).expectNext(new Pojo("foofoo", "barbar")).expectComplete().verify();
}
use of org.springframework.core.io.buffer.DataBuffer in project spring-framework by spring-projects.
the class Jaxb2XmlDecoderTests method decodeMultipleXmlRootElement.
@Test
public void decodeMultipleXmlRootElement() throws Exception {
Flux<DataBuffer> source = Flux.just(stringBuffer(POJO_CHILD));
Flux<Object> output = this.decoder.decode(source, ResolvableType.forClass(Pojo.class), null, Collections.emptyMap());
StepVerifier.create(output).expectNext(new Pojo("foo", "bar")).expectNext(new Pojo("foofoo", "barbar")).expectComplete().verify();
}
use of org.springframework.core.io.buffer.DataBuffer in project spring-framework by spring-projects.
the class Jaxb2XmlEncoderTests method encode.
@Test
public void encode() throws Exception {
Flux<Pojo> source = Flux.just(new Pojo("foofoo", "barbar"), new Pojo("foofoofoo", "barbarbar"));
Flux<DataBuffer> output = this.encoder.encode(source, this.bufferFactory, ResolvableType.forClass(Pojo.class), MediaType.APPLICATION_XML, Collections.emptyMap());
StepVerifier.create(output).consumeNextWith(dataBuffer -> {
try {
String s = DataBufferTestUtils.dumpString(dataBuffer, StandardCharsets.UTF_8);
assertThat(s, isSimilarTo("<?xml version='1.0' encoding='UTF-8' standalone='yes'?>" + "<pojo><bar>barbar</bar><foo>foofoo</foo></pojo>"));
} finally {
DataBufferUtils.release(dataBuffer);
}
}).expectComplete().verify();
}
use of org.springframework.core.io.buffer.DataBuffer 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