Skip to content

Customization for ObjectReader and ObjectWriter #28401

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed

Conversation

jlaber
Copy link
Contributor

@jlaber jlaber commented Apr 30, 2022

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.

Allows customization on subclasses of:
AbstractJackson2HttpMessageConverter, AbstractJackson2Decoder, or AbstractJackson2Encoder
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Apr 30, 2022
…s-squash

# Conflicts:
#	spring-web/src/main/java/org/springframework/http/codec/json/AbstractJackson2Encoder.java
@jlaber
Copy link
Contributor Author

jlaber commented Jun 28, 2022

Is there a process to get a PR looked at?

Copy link
Contributor

@rstoyanchev rstoyanchev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally looks fine, so scheduling this for the next 6.0 milestone. Just a couple of comments below.

@rstoyanchev rstoyanchev added in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Jul 22, 2022
@rstoyanchev rstoyanchev added this to the 6.0.0-M6 milestone Jul 22, 2022
@rstoyanchev rstoyanchev modified the milestones: 6.0.0-M6, 6.0.0-RC1 Sep 14, 2022
rstoyanchev pushed a commit that referenced this pull request Sep 23, 2022
Allows customization from subclasses of
AbstractJackson2HttpMessageConverter, AbstractJackson2Decoder, and
AbstractJackson2Encoder

See gh-28401
@rstoyanchev
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants