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

Missing JsonNode field deserialized to null instead of NullNode #3389

Closed
the8tre opened this issue Jan 31, 2022 · 3 comments
Closed

Missing JsonNode field deserialized to null instead of NullNode #3389

the8tre opened this issue Jan 31, 2022 · 3 comments
Labels
will-not-fix Closed as either non-issue or something not planned to be worked on

Comments

@the8tre
Copy link

the8tre commented Jan 31, 2022

Describe the bug
There's a behavior change between 2.12.6 and 2.13.0.
Until then a missing JsonNode field was deserialized as a NullNode and it now is deserialized to Java null.

Version information
Behavior change occurs since 2.13.0

To Reproduce

    public static class MyObject {
        public JsonNode jsonNode;
        @JsonCreator
        public MyObject(@JsonProperty("jsonNode") JsonNode jsonNode) {
            this.jsonNode = jsonNode;
        }
    }
    
    @Test
    void nullNodeTest() throws JsonMappingException, JsonProcessingException {
        String json = "{}";
        ObjectMapper mapper = new ObjectMapper();
        MyObject object = mapper.readValue(json, MyObject.class);
        assertNotNull(object.jsonNode);
        assertInstanceOf(NullNode.class, object.jsonNode);
    }

With 2.12.6this test passes successfully.
Since 2.13.0it fails as jsonNode is deserialized to null.

Expected behavior
After I've read a lot of issues related to null and NullNode and I can't tell for sure what should be the expected behavior.
But for sure that change can break some code relying on that.

Additional context
The change introduced in 2.13.0 to fix #3214 seems to be somewhat linked to this behavior change.

@the8tre the8tre added the to-evaluate Issue that has been received but not yet evaluated label Jan 31, 2022
@wix-andriusb
Copy link

@cowtowncoder Is this the new expected behavior?
Or can we expected this to be reverted?

@wix-andriusb
Copy link

looks like this is intended: #3214 (comment)

@cowtowncoder
Copy link
Member

Correct: as per #3214 this works as intended and is the new expected behavior.

If coercion from null to NullNode is preferred, it should be possible to add "null conversion" logic (either with @JsonSetter, or ObjectMappers configuration) using Nulls.AS_EMPTY for JsonNode.
But distinction between "absent" and "explicit 'null' token" required this change.

I am not sure if this is tested and would be interested in seeing if it does work or not yet (there is need for deseralizers to help). Tests for POJOs, enums etc can be found from:

src/test/java/com/fasterxml/jackson/databind/deser/filter/

(like NullConversionsPojoTest.java)

and this also shows how to configure null conversions (via annotations or for ObjectMapper).

mjsax added a commit to confluentinc/ksql that referenced this issue Apr 27, 2022
Jackson was bumped upstream: confluentinc/common#446

Version 2.13 returns null instead of NullNode (cf FasterXML/jackson-databind#3389)
mjsax added a commit to confluentinc/ksql that referenced this issue Apr 27, 2022
Jackson was bumped upstream: confluentinc/common#446

Version 2.13 returns null instead of NullNode (cf FasterXML/jackson-databind#3389)
mjsax added a commit to confluentinc/ksql that referenced this issue Apr 27, 2022
Jackson was bumped upstream: confluentinc/common#446
    
Version 2.13 returns null instead of NullNode (cf FasterXML/jackson-databind#3389)
mjsax added a commit to confluentinc/ksql that referenced this issue Apr 27, 2022
@cowtowncoder cowtowncoder added will-not-fix Closed as either non-issue or something not planned to be worked on and removed to-evaluate Issue that has been received but not yet evaluated labels Aug 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
will-not-fix Closed as either non-issue or something not planned to be worked on
Projects
None yet
Development

No branches or pull requests

3 participants