Unwrap MappingJacksonValue before selecting ObjectMapper

See gh-28045
This commit is contained in:
rstoyanchev
2022-03-16 07:37:20 +00:00
parent cb39b07088
commit 21d61316be
2 changed files with 31 additions and 4 deletions

View File

@@ -231,6 +231,29 @@ public class Jackson2JsonEncoderTests extends AbstractEncoderTests<Jackson2JsonE
);
}
@Test // gh-28045
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.forClass(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));
testEncode(Mono.just(jacksonValue), type, halMediaType, Collections.emptyMap(), step -> step
.consumeNextWith(expectString("{\n \"withView1\" : \"with\"\n}").andThen(DataBufferUtils::release))
.verifyComplete()
);
}
@Test // gh-22771
public void encodeWithFlushAfterWriteOff() {
ObjectMapper mapper = new ObjectMapper();