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

Change ObjectMapper.valueToTree() to convert null to NullNode #2430

Closed
cowtowncoder opened this issue Aug 23, 2019 · 2 comments
Closed

Change ObjectMapper.valueToTree() to convert null to NullNode #2430

cowtowncoder opened this issue Aug 23, 2019 · 2 comments
Milestone

Comments

@cowtowncoder
Copy link
Member

It looks like valueToTree() method will currently simple return null if null is passed.
For many other conversions this makes sense, but in case of JsonNode, it would make more sense to return NullNode.

@cowtowncoder cowtowncoder modified the milestones: 2.10.0, 2.10.0.pr2 Aug 23, 2019
@cowtowncoder cowtowncoder changed the title Change ObjectMapper.valueToTree() to convert null to NullNode Change ObjectMapper.valueToTree() to convert null to NullNode; treeToValue() NullNode to null Aug 23, 2019
@cowtowncoder cowtowncoder changed the title Change ObjectMapper.valueToTree() to convert null to NullNode; treeToValue() NullNode to null Change ObjectMapper.valueToTree() to convert null to NullNode Aug 23, 2019
@asnare
Copy link

asnare commented Oct 18, 2019

Interestingly, I think this change leads to a subtle behaviour change when combined with Jdk8Module. We have a test for a @JsonCreator method that has an Optional<JsonNode> parameter. Prior to this change a field that wasn't present would get mapped to Optional.empty(), whereas now it gets mapped to Optional.of(NullNode).

I guess it's splitting hairs, but previously this meant it was possible to differentiate between an attribute that was missing entirely and one that was present but with null assigned. Now they seem to be treated as exactly equivalent. (Is this correct?)

@cowtowncoder
Copy link
Member Author

@asnare Hmmh. So, two things should not be directly related: treeToValue() has specific handling where null from JsonParser is received. It should not be used by code that handles @JsonCreator values: that should just get null. I do agree that Optional<JsonNode from null token should become Optional.empty(), and not Optional.of(nullNode). Question then is... why did behavior change?

IF you can easily reproduce this, could you please file an issue against jackson-modules-java8?

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

No branches or pull requests

2 participants