spring-framework icon indicating copy to clipboard operation
spring-framework copied to clipboard

Customization for ObjectReader and ObjectWriter

Open jlaber opened this issue 2 years ago • 1 comments

We are finding some needs to customize the ObjectReader and ObjectWriter for Jackson serialization and deserialization, while leveraging as much default behavior as possible for both our web services running in webflux and webmvc.

After doing some investigation, it looks like AbstractJackson2Encoder already provided a customize method: https://github.com/paychex/spring-framework/blob/main/spring-web/src/main/java/org/springframework/http/codec/json/AbstractJackson2Encoder.java#L315

There was however no consistency to be able to do this with the ObjectReader in the AbstractJackson2Decoder or on the webmvc side, as neither the ObjectWriter or ObjectReader had customization methods in AbstractJackson2HttpMessageConverter. This PR is for bringing the consistency so that we can now customize both for both webflux and webmvc.

This PR goes one step further as well on AbstractJackson2Decoder and AbstractJackson2Encoder to allow the customization as well from the reactive flow that will allow the ability to get contextual information from the current reactive flow for the customization which is another need we have.

jlaber avatar Apr 30 '22 01:04 jlaber

Is there a process to get a PR looked at?

jlaber avatar Jun 28 '22 12:06 jlaber

I've gone with a slightly different solution. As there was an existing protected customizeWrite method, I've passed the Reactor ContextView as one of the hints in the hints input map. This works well also with the fact that a Reactor context isn't always available given the synchronous encode and decode methods that can be used.

rstoyanchev avatar Sep 23 '22 15:09 rstoyanchev