-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Description
Search before asking
- I searched in the issues and found nothing similar.
Describe the bug
There is a discrepency between the asString behavior of NullNode on Jackson 3 and Jackson 2.
Version Information
3.0.1 and 2.20.1
Reproduction
If we take:
System.out.println(NullNode.getInstance().asText());
System.out.println(NullNode.getInstance().asText("default"));Expected behavior
With Jackson 2 it prints:
null
default
With Jackson 3 it prints:
i.e. both methods return an empty String on Jackson 3. However, with Jackson 2
Additional context
I did find #5034, but I could not understand the reasoning for the change of the asString(String). For asString() you can argue that maybe an empty string is fine, but why empty string for asString(String)? I also did see #5287 which makes stringValue(String) return the default value for null nodes.
We have a lot of parsing code that uses JsonNode and we use a lot object.path("someProperty").asText("default") to get a value for it. The pattern for this now should be object.path("someProperty").stringValue("default"), but this is something that did not exist in Jackson 2.