Spring Webflux deserialize json with and without unwrapping

239 views Asked by At

I'm consuming REST services with Spring Webflux using bean deserialization via Jackson, i.e. ObjectMapper. Some requests need the response object to be unwrapped, some not.

I'm well aware that I can achieve unwrapping wit a bean like

@Bean
public Jackson2ObjectMapperBuilder unwrappingJacksonBuilder() {
    Jackson2ObjectMapperBuilder builder = new Jackson2ObjectMapperBuilder();
    builder.featuresToEnable(DeserializationFeature.UNWRAP_ROOT_VALUE);
    return builder;
} 

but this causes all response objects to be unwrapped.

I have tried to use @JsonDeserialize(MyUnwrappingDeserializer.class) for the objects which need unwrapping, but I assume there's a much simpler way to do this.

Second idea was to use 2 different ObjectMapper-Beans, one unwrapping and the other one not, but I am missing the link how to configure the respective WebClients with the different ObjectMappers.

Has anyone a hint for this problem?

0

There are 0 answers