Skip to content

JacksonAutoConfiguration wipes out modules registered in Jackson2ObjectMapperBuilderCustomizers with higher precedence #39592

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
hesselapplications opened this issue Feb 15, 2024 · 3 comments
Labels
status: superseded An issue that has been superseded by another

Comments

@hesselapplications
Copy link

hesselapplications commented Feb 15, 2024

If I provide a Jackson2ObjectMapperBuilderCustomizer with @Order(Ordered.HIGHEST_PRECEDENCE) it gets applied before the boot default customizer in JacksonAutoConfiguration. This is to be expected. What is not expected however is that the boot customizer wipes out any modules registered by higher precedence customizers.

Believe the fix is to update this line to use the consumer variant introduced here

I am using boot 3.1.8
Thanks for everything you do.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Feb 15, 2024
@wilkinsona
Copy link
Member

Thanks, @hesselapplications.

Our customizer is intentionally ordered at 0 to allow other customisers to be ordered either before or after it. I think you could avoid your problem by giving your customizer a lower precedence (any value greater than zero).

It's possible, although perhaps unlikely, that someone may be relying on the current behavior. If we switched to using the additive variant they may end up with Jackson using unwanted modules. As such, I think we may need to wait until 3.3 to make any changes here to avoid a potentially breaking change in a maintenance release.

Out of interest, and to help us to understand how much of a problem this is for you, do you need to be able to configure the modules programatically or could you define them as beans so that the standard customizer registers them all?

@wilkinsona wilkinsona added the status: waiting-for-feedback We need additional information before we can continue label Feb 21, 2024
@hesselapplications
Copy link
Author

hesselapplications commented Feb 21, 2024

could avoid your problem by giving your customizer a lower precedence

Yes additive modules do behave correctly with this approach

Out of interest...

Our use case is we have an organization wide library included in every service. Within that we want to provide some org wide de/serialization defaults and custom modules via a customizer. We want the standard spring customizer to run after that so that the services can provide their own customizations on top of the org defaults in standard spring fashion. That way they are none the wiser to what is happening in the org library, no need to define their customizers at order library customizer + 1

I believe you are right that registering the modules as beans would allow our use case to work though. Thank you for the suggestion

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Feb 21, 2024
@philwebb philwebb added type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged status: feedback-provided Feedback has been provided labels Apr 22, 2024
@philwebb philwebb added this to the 3.x milestone Apr 22, 2024
@wilkinsona wilkinsona changed the title JacksonAutoConfiguration wipes out modules registered in Jackson2ObjectMapperBuilderCustomizer's with higher precedence JacksonAutoConfiguration wipes out modules registered in Jackson2ObjectMapperBuilderCustomizers with higher precedence May 3, 2024
@mhalbritter
Copy link
Contributor

Superseded by #42836.

@mhalbritter mhalbritter closed this as not planned Won't fix, can't repro, duplicate, stale Oct 28, 2024
@mhalbritter mhalbritter added status: superseded An issue that has been superseded by another and removed type: enhancement A general enhancement labels Oct 28, 2024
@mhalbritter mhalbritter removed this from the 3.x milestone Oct 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: superseded An issue that has been superseded by another
Projects
None yet
Development

No branches or pull requests

5 participants