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());
}
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());
}
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);
}
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);
}
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);
}
Aggregations