Skip to content
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

Deserialization behavior change with @JsonCreator and @ConstructorProperties between 2.17 and 2.18 #4908

Closed
1 task done
gssbzn opened this issue Jan 15, 2025 · 11 comments
Closed
1 task done
Labels
Milestone

Comments

@gssbzn
Copy link

gssbzn commented Jan 15, 2025

Search before asking

  • I searched in the issues and found nothing similar.

Describe the bug

We maintain a large codebase which has some legacy classes that use Hungarian notation and lombok,

Deserialization used to work up until the 2.18 update where jackson is no longer respecting the @ConstructorProperties to match the constructor properties and we are now seeing cannot deserialize from Object value (no delegate- or property-based Creator) errors.

This may be related to INFER_CREATOR_FROM_CONSTRUCTOR_PROPERTIES and the recent rewrite POJO Property Introspection

Version Information

2.18.2

Reproduction

@Test
  void deserialization() throws JsonProcessingException {
    var json =
        """
{
  "value": "test"
}
""";
    var result = new ObjectMapper().readValue(json, Something.class); // throws error

    assertEquals("test", result.getValue());
  }

  private static class Something {
    @JsonProperty("value")
    private final String _value;

    String getValue() {
      return _value;
    }

    @JsonCreator
    @ConstructorProperties({"value"})
    Something(String pValue) {
      _value = pValue;
    }
  }

Expected behavior

jackson should be able to leverage @ConstructorProperties for the @JsonCreator

Additional context

No response

@gssbzn gssbzn added the to-evaluate Issue that has been received but not yet evaluated label Jan 15, 2025
@cowtowncoder
Copy link
Member

Thank you for reporting this @gssbzn. It definitely sounds like bug.

@cowtowncoder
Copy link
Member

cowtowncoder commented Jan 25, 2025

Oh. But this looks odd:

    @JsonCreator
    @ConstructorProperties({"value"})
    Something(String pValue) {
      _value = pValue;
    }

Use of @JsonCreator is redundant. So while it should not cause problems, I'd remove that just as basic clean up. And it might also work around the issue (haven't checked yet but guessing it might actually be causing problem).
That is: you don't need @JsonCreator if you have @ConstructorProperties: latter implies former (with mode = JsonCreator.Mode.PROPERTIES)

@cowtowncoder cowtowncoder modified the milestones: 2.18.0, 2.18.3 Jan 26, 2025
@cowtowncoder cowtowncoder added 2.18 and removed to-evaluate Issue that has been received but not yet evaluated labels Jan 26, 2025
@cowtowncoder
Copy link
Member

Found the reason: @JsonCreator has default mode (Mode.DEFAULT) which overrides @CosntructorProperties-implied Mode.PROPERTIES. Will fix.

cowtowncoder added a commit that referenced this issue Jan 26, 2025
@cowtowncoder
Copy link
Member

Fixed. Thank you @gssbzn for reporting this! Will be in 2.18.3 release.

@nipanwar77
Copy link

nipanwar77 commented Feb 18, 2025

Hi @cowtowncoder , since this is a part of 2.18.3, when is it expected to be released any timeline? We need the patch urgently and there is no due date assigned

@pjfanning
Copy link
Member

@nipanwar77 can't you use 2.17 until new releases are made?

@nipanwar77
Copy link

@pjfanning We need to move to spring-boot 3.4.0 for security reasons and we are not able to use 2.17 with it.

@deepakraghav0
Copy link

@pjfanning I checked that there is no open issue for 2.18.3 at your end, can we get patch soon :)

@pjfanning
Copy link
Member

pjfanning commented Feb 18, 2025

@pjfanning I checked that there is no open issue for 2.18.3 at your end, can we get patch soon :)

There is other work happening. 2.18.3 will happen when it happens. Please provide a detailed description of why you can't use an older version of Jackson. Releases involve a lot of work.

Have you even tried overriding the Jackson version in your build? What proof do you that spring-boot needs an exact version of Jackson and can't be used with other recent versions of Jackson?

@cowtowncoder
Copy link
Member

@deepakraghav0 Things are bit hectic with 3.0.0-rc1 work, so 2.18.3 will probably happen in early March. Like @pjfanning indicated, full release takes quite a bit of effort (2.5 - 4 hours of my time) and I don't work on Jackson full time so unfortunately finding chunk of "free" time is not always easy.
(and unfortunately there's neither easy way to speed up release or delegate to other team members).

But I definitely also want to get 2.18.3 out, it's pretty well loaded with fixes:

https://github.com/FasterXML/jackson/wiki/Jackson-Release-2.18.3

@deepakraghav0
Copy link

Hello @cowtowncoder , sorry for the late reply. I noticed that version 2.18.3 was released on February 28th. Thanks for the update!

@pjfanning we have some complex scenarios that require version 2.18.3. Now that it is available, it should work for us.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants