Search in sources :

Example 26 with ResolvableType

use of cn.taketoday.core.ResolvableType in project today-infrastructure by TAKETODAY.

the class Jackson2JsonEncoderTests method jacksonValue.

@Test
public void jacksonValue() {
    JacksonViewBean bean = new JacksonViewBean();
    bean.setWithView1("with");
    bean.setWithView2("with");
    bean.setWithoutView("without");
    MappingJacksonValue jacksonValue = new MappingJacksonValue(bean);
    jacksonValue.setSerializationView(MyJacksonView1.class);
    ResolvableType type = ResolvableType.fromClass(MappingJacksonValue.class);
    testEncode(Mono.just(jacksonValue), type, step -> step.consumeNextWith(expectString("{\"withView1\":\"with\"}").andThen(DataBufferUtils::release)).verifyComplete(), null, Collections.emptyMap());
}
Also used : MappingJacksonValue(cn.taketoday.http.converter.json.MappingJacksonValue) ResolvableType(cn.taketoday.core.ResolvableType) Test(org.junit.jupiter.api.Test)

Example 27 with ResolvableType

use of cn.taketoday.core.ResolvableType in project today-infrastructure by TAKETODAY.

the class Jackson2JsonEncoderTests method jacksonValueUnwrappedBeforeObjectMapperSelection.

// gh-28045
@Test
public void jacksonValueUnwrappedBeforeObjectMapperSelection() {
    JacksonViewBean bean = new JacksonViewBean();
    bean.setWithView1("with");
    bean.setWithView2("with");
    bean.setWithoutView("without");
    MappingJacksonValue jacksonValue = new MappingJacksonValue(bean);
    jacksonValue.setSerializationView(MyJacksonView1.class);
    ResolvableType type = ResolvableType.fromClass(MappingJacksonValue.class);
    MediaType halMediaType = MediaType.parseMediaType("application/hal+json");
    ObjectMapper mapper = new ObjectMapper().configure(SerializationFeature.INDENT_OUTPUT, true);
    this.encoder.registerObjectMappersForType(JacksonViewBean.class, map -> map.put(halMediaType, mapper));
    // output below is different between Unix and Windows
    String ls = System.lineSeparator();
    testEncode(Mono.just(jacksonValue), type, halMediaType, Collections.emptyMap(), step -> step.consumeNextWith(expectString("{" + ls + "  \"withView1\" : \"with\"" + ls + "}").andThen(DataBufferUtils::release)).verifyComplete());
}
Also used : MediaType(cn.taketoday.http.MediaType) MappingJacksonValue(cn.taketoday.http.converter.json.MappingJacksonValue) ResolvableType(cn.taketoday.core.ResolvableType) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.jupiter.api.Test)

Example 28 with ResolvableType

use of cn.taketoday.core.ResolvableType in project today-infrastructure by TAKETODAY.

the class Jackson2CborDecoderTests method decodeToMono.

@Override
@Test
public void decodeToMono() {
    List<Pojo> expected = Arrays.asList(pojo1, pojo2);
    Flux<DataBuffer> input = Flux.just(expected).map(this::writeObject).flatMap(this::dataBuffer);
    ResolvableType elementType = ResolvableType.fromClassWithGenerics(List.class, Pojo.class);
    testDecodeToMono(input, elementType, step -> step.expectNext(expected).expectComplete().verify(), null, null);
}
Also used : Pojo(cn.taketoday.http.codec.Pojo) ResolvableType(cn.taketoday.core.ResolvableType) DataBuffer(cn.taketoday.core.io.buffer.DataBuffer) Test(org.junit.jupiter.api.Test)

Example 29 with ResolvableType

use of cn.taketoday.core.ResolvableType in project today-infrastructure by TAKETODAY.

the class Jackson2JsonDecoderTests method decodeAscii.

@Test
@SuppressWarnings("unchecked")
public void decodeAscii() {
    Flux<DataBuffer> input = Flux.concat(stringBuffer("{\"foo\":\"bar\"}", StandardCharsets.US_ASCII));
    ResolvableType type = ResolvableType.fromType(new TypeReference<Map<String, String>>() {
    });
    testDecode(input, type, step -> step.assertNext(value -> assertThat((Map<String, String>) value).containsEntry("foo", "bar")).verifyComplete(), MediaType.parseMediaType("application/json; charset=us-ascii"), null);
}
Also used : ResolvableType(cn.taketoday.core.ResolvableType) Map(java.util.Map) DataBuffer(cn.taketoday.core.io.buffer.DataBuffer) Test(org.junit.jupiter.api.Test)

Example 30 with ResolvableType

use of cn.taketoday.core.ResolvableType in project today-infrastructure by TAKETODAY.

the class Jackson2JsonDecoderTests method decodeToMono.

@Override
@Test
public void decodeToMono() {
    Flux<DataBuffer> input = Flux.concat(stringBuffer("[{\"bar\":\"b1\",\"foo\":\"f1\"},"), stringBuffer("{\"bar\":\"b2\",\"foo\":\"f2\"}]"));
    ResolvableType elementType = ResolvableType.fromClassWithGenerics(List.class, Pojo.class);
    testDecodeToMonoAll(input, elementType, step -> step.expectNext(Arrays.asList(new Pojo("f1", "b1"), new Pojo("f2", "b2"))).expectComplete().verify(), null, null);
}
Also used : Pojo(cn.taketoday.http.codec.Pojo) ResolvableType(cn.taketoday.core.ResolvableType) DataBuffer(cn.taketoday.core.io.buffer.DataBuffer) Test(org.junit.jupiter.api.Test)

Aggregations

ResolvableType (cn.taketoday.core.ResolvableType)159 Test (org.junit.jupiter.api.Test)106 DataBuffer (cn.taketoday.core.io.buffer.DataBuffer)30 Map (java.util.Map)24 Pojo (cn.taketoday.http.codec.Pojo)20 List (java.util.List)16 MediaType (cn.taketoday.http.MediaType)15 MockConfigurationPropertySource (cn.taketoday.context.properties.source.MockConfigurationPropertySource)14 Flux (reactor.core.publisher.Flux)12 Mono (reactor.core.publisher.Mono)10 Resource (cn.taketoday.core.io.Resource)8 Nullable (cn.taketoday.lang.Nullable)8 ArrayList (java.util.ArrayList)8 IOException (java.io.IOException)7 MultiValueMap (cn.taketoday.core.MultiValueMap)6 ReactiveHttpOutputMessage (cn.taketoday.http.ReactiveHttpOutputMessage)6 ServerSentEvent (cn.taketoday.http.codec.ServerSentEvent)6 MimeType (cn.taketoday.util.MimeType)6 Arrays (java.util.Arrays)6 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)5