use of org.springframework.http.codec.Pojo in project spring-framework by spring-projects.
the class Jackson2JsonDecoderTests method decodeToList.
@Test
public void decodeToList() throws Exception {
Flux<DataBuffer> source = Flux.just(stringBuffer("[{\"bar\":\"b1\",\"foo\":\"f1\"},{\"bar\":\"b2\",\"foo\":\"f2\"}]"));
ResolvableType elementType = ResolvableType.forClassWithGenerics(List.class, Pojo.class);
Mono<Object> mono = new Jackson2JsonDecoder().decodeToMono(source, elementType, null, Collections.emptyMap());
StepVerifier.create(mono).expectNext(Arrays.asList(new Pojo("f1", "b1"), new Pojo("f2", "b2"))).expectComplete().verify();
}
use of org.springframework.http.codec.Pojo in project spring-framework by spring-projects.
the class Jackson2JsonDecoderTests method decodePojo.
@Test
public void decodePojo() throws Exception {
Flux<DataBuffer> source = Flux.just(stringBuffer("{\"foo\": \"foofoo\", \"bar\": \"barbar\"}"));
ResolvableType elementType = ResolvableType.forClass(Pojo.class);
Flux<Object> flux = new Jackson2JsonDecoder().decode(source, elementType, null, Collections.emptyMap());
StepVerifier.create(flux).expectNext(new Pojo("foofoo", "barbar")).expectComplete().verify();
}
use of org.springframework.http.codec.Pojo in project spring-framework by spring-projects.
the class WebClientIntegrationTests method postJsonPojo.
@Test
public void postJsonPojo() throws Exception {
this.server.enqueue(new MockResponse().setHeader("Content-Type", "application/json").setBody("{\"bar\":\"BARBAR\",\"foo\":\"FOOFOO\"}"));
Mono<Pojo> result = this.webClient.post().uri("/pojo/capitalize").accept(MediaType.APPLICATION_JSON).contentType(MediaType.APPLICATION_JSON).exchange(fromObject(new Pojo("foofoo", "barbar"))).then(response -> response.bodyToMono(Pojo.class));
StepVerifier.create(result).consumeNextWith(p -> assertEquals("BARBAR", p.getBar())).expectComplete().verify(Duration.ofSeconds(3));
RecordedRequest recordedRequest = server.takeRequest();
Assert.assertEquals(1, server.getRequestCount());
Assert.assertEquals("/pojo/capitalize", recordedRequest.getPath());
Assert.assertEquals("{\"foo\":\"foofoo\",\"bar\":\"barbar\"}", recordedRequest.getBody().readUtf8());
Assert.assertEquals("chunked", recordedRequest.getHeader(HttpHeaders.TRANSFER_ENCODING));
Assert.assertEquals("application/json", recordedRequest.getHeader(HttpHeaders.ACCEPT));
Assert.assertEquals("application/json", recordedRequest.getHeader(HttpHeaders.CONTENT_TYPE));
}
use of org.springframework.http.codec.Pojo in project spring-framework by spring-projects.
the class Jackson2JsonDecoderTests method decodeToFlux.
@Test
public void decodeToFlux() throws Exception {
Flux<DataBuffer> source = Flux.just(stringBuffer("[{\"bar\":\"b1\",\"foo\":\"f1\"},{\"bar\":\"b2\",\"foo\":\"f2\"}]"));
ResolvableType elementType = ResolvableType.forClass(Pojo.class);
Flux<Object> flux = new Jackson2JsonDecoder().decode(source, elementType, null, Collections.emptyMap());
StepVerifier.create(flux).expectNext(new Pojo("f1", "b1")).expectNext(new Pojo("f2", "b2")).expectComplete().verify();
}
use of org.springframework.http.codec.Pojo 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();
}
Aggregations