Skip to content

Auto-configure Jackson contructor detector to ConstructorDetector.USE_PROPERTIES_BASED by default #26023

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
lpandzic opened this issue Apr 12, 2021 · 1 comment
Labels
status: declined A suggestion or change that we don't feel we should currently apply

Comments

@lpandzic
Copy link

I believe Jackson Auto Configuration in Spring should set ConstructorDetector.USE_PROPERTIES_BASED flag out of the box:

objectMapper.setConstructorDetector(com.fasterxml.jackson.databind.cfg.ConstructorDetector.USE_PROPERTIES_BASED);

Background can be found here: FasterXML/jackson-databind#1498 and my tldr version is (I've been involved since the start of this in 2014...): Due to backwards compatibility concerns this can't be changed in Jackson itself but on the other hand this surprises a lot of Jackson users as the whole Java industry moves slowly forward to immutable by default way of thinking.

With this enabled users should be able to deserialize classes without any exceptions or surprises:

class Foo {
    private final Bar bar;

    Foo(Bar bar) {
        this.bar = bar;
    }
}
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Apr 12, 2021
@snicoll snicoll changed the title Jackson auto configuration - ConstructorDetector.USE_PROPERTIES_BASED Auto-configure Jackson contructor detector to ConstructorDetector.USE_PROPERTIES_BASED by default Apr 12, 2021
@philwebb philwebb added for: team-meeting An issue we'd like to discuss as a team to make progress and removed for: team-meeting An issue we'd like to discuss as a team to make progress labels Apr 12, 2021
@snicoll snicoll added the for: team-meeting An issue we'd like to discuss as a team to make progress label Jun 14, 2021
@philwebb
Copy link
Member

philwebb commented Jul 7, 2021

We discussed this today on a team call and we're currently not keen to change the default. We think it's best if we keep ourselves aligned with the Jackson defaults as much as possible. Perhaps Jackson will reconsider the default on 3.0?

We do think it's worth making it easier to change the setting for those that wish to. I've opened #27178 to see if we can add a new property for that.

@philwebb philwebb closed this as completed Jul 7, 2021
@philwebb philwebb added status: declined A suggestion or change that we don't feel we should currently apply and removed for: team-meeting An issue we'd like to discuss as a team to make progress status: waiting-for-triage An issue we've not yet triaged labels Jul 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: declined A suggestion or change that we don't feel we should currently apply
Projects
None yet
Development

No branches or pull requests

4 participants