use of org.springframework.core.io.buffer.DataBuffer 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.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();
}
Aggregations