Search in sources :

Example 1 with Pojo

use of cn.taketoday.http.codec.Pojo in project today-infrastructure by TAKETODAY.

the class Jackson2CborEncoderTests method encode.

@Test
public void encode() {
    Pojo value = new Pojo("foo", "bar");
    DataBuffer result = encoder.encodeValue(value, this.bufferFactory, ResolvableType.fromClass(Pojo.class), CBOR_MIME_TYPE, null);
    pojoConsumer(value).accept(result);
}
Also used : Pojo(cn.taketoday.http.codec.Pojo) DataBuffer(cn.taketoday.core.io.buffer.DataBuffer) Test(org.junit.jupiter.api.Test)

Example 2 with Pojo

use of cn.taketoday.http.codec.Pojo in project today-infrastructure by TAKETODAY.

the class Jackson2CborEncoderTests method encodeStream.

@Test
public void encodeStream() {
    Pojo pojo1 = new Pojo("foo", "bar");
    Pojo pojo2 = new Pojo("foofoo", "barbar");
    Pojo pojo3 = new Pojo("foofoofoo", "barbarbar");
    Flux<Pojo> input = Flux.just(pojo1, pojo2, pojo3);
    ResolvableType type = ResolvableType.fromClass(Pojo.class);
    assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> encoder.encode(input, this.bufferFactory, type, CBOR_MIME_TYPE, null));
}
Also used : Pojo(cn.taketoday.http.codec.Pojo) ResolvableType(cn.taketoday.core.ResolvableType) Test(org.junit.jupiter.api.Test)

Example 3 with Pojo

use of cn.taketoday.http.codec.Pojo in project today-infrastructure by TAKETODAY.

the class Jackson2JsonEncoderTests method encodeWithFlushAfterWriteOff.

// gh-22771
@Test
public void encodeWithFlushAfterWriteOff() {
    ObjectMapper mapper = new ObjectMapper();
    mapper.configure(SerializationFeature.FLUSH_AFTER_WRITE_VALUE, false);
    Jackson2JsonEncoder encoder = new Jackson2JsonEncoder(mapper);
    Flux<DataBuffer> result = encoder.encode(Flux.just(new Pojo("foo", "bar")), this.bufferFactory, ResolvableType.fromClass(Pojo.class), MimeTypeUtils.APPLICATION_JSON, Collections.emptyMap());
    StepVerifier.create(result).consumeNextWith(expectString("[{\"foo\":\"foo\",\"bar\":\"bar\"}]")).expectComplete().verify(Duration.ofSeconds(5));
}
Also used : Pojo(cn.taketoday.http.codec.Pojo) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DataBuffer(cn.taketoday.core.io.buffer.DataBuffer) Test(org.junit.jupiter.api.Test)

Example 4 with Pojo

use of cn.taketoday.http.codec.Pojo in project today-infrastructure by TAKETODAY.

the class Jackson2JsonEncoderTests method encodeAscii.

@Test
public void encodeAscii() {
    Mono<Object> input = Mono.just(new Pojo("foo", "bar"));
    testEncode(input, ResolvableType.fromClass(Pojo.class), step -> step.consumeNextWith(expectString("{\"foo\":\"foo\",\"bar\":\"bar\"}")).verifyComplete(), new MimeType("application", "json", StandardCharsets.US_ASCII), null);
}
Also used : Pojo(cn.taketoday.http.codec.Pojo) MimeType(cn.taketoday.util.MimeType) Test(org.junit.jupiter.api.Test)

Example 5 with Pojo

use of cn.taketoday.http.codec.Pojo in project today-infrastructure by TAKETODAY.

the class Jackson2JsonEncoderTests method encodeNonStream.

@Test
public void encodeNonStream() {
    Flux<Pojo> input = Flux.just(new Pojo("foo", "bar"), new Pojo("foofoo", "barbar"), new Pojo("foofoofoo", "barbarbar"));
    testEncode(input, Pojo.class, step -> step.consumeNextWith(expectString("[" + "{\"foo\":\"foo\",\"bar\":\"bar\"}," + "{\"foo\":\"foofoo\",\"bar\":\"barbar\"}," + "{\"foo\":\"foofoofoo\",\"bar\":\"barbarbar\"}]").andThen(DataBufferUtils::release)).verifyComplete());
}
Also used : Pojo(cn.taketoday.http.codec.Pojo) Test(org.junit.jupiter.api.Test)

Aggregations

Pojo (cn.taketoday.http.codec.Pojo)24 Test (org.junit.jupiter.api.Test)24 DataBuffer (cn.taketoday.core.io.buffer.DataBuffer)14 ResolvableType (cn.taketoday.core.ResolvableType)12 MimeType (cn.taketoday.util.MimeType)6 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)6 DataBufferUtils (cn.taketoday.core.io.buffer.DataBufferUtils)5 AbstractEncoderTests (cn.taketoday.core.codec.AbstractEncoderTests)4 DataBufferUtils.release (cn.taketoday.core.io.buffer.DataBufferUtils.release)4 APPLICATION_XML (cn.taketoday.http.MediaType.APPLICATION_XML)4 ServerSentEvent (cn.taketoday.http.codec.ServerSentEvent)4 Jackson2ObjectMapperBuilder (cn.taketoday.http.converter.json.Jackson2ObjectMapperBuilder)4 MappingIterator (com.fasterxml.jackson.databind.MappingIterator)4 IOException (java.io.IOException)4 UncheckedIOException (java.io.UncheckedIOException)4 Arrays (java.util.Arrays)4 List (java.util.List)4 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)4 Flux (reactor.core.publisher.Flux)4 Mono (reactor.core.publisher.Mono)4