jackson-javax-json
jackson-javax-json copied to clipboard
Fix bug with JacksonObject#getString(String, String) and null values
In JSR 353, the JsonObject#getString(String name, String defaultValue) method returns defaultValue if the value associated with name in the source JSON is null, e.g. { "foo": null }. In this implementation, the call to _delegate#get returns a NullNode instead of the value null, which means the return value is NullNode#asText (i.e. the literal string "null") instead of the default value.
This is fixed by modifying the equivalent method in JacksonObject so that we check the value of JsonNode#isNull if the null check passes, and return the default value if isNull returns true. Although getInt(String, int) and getBoolean(String, boolean) work correctly in this case because of how asInt and asBoolean are implemented, the fix is applied to those methods as well.
It's possible that this could have been fixed by simply calling JsonNode#asText(defaultValue), but that method isn't available in the version of Jackson used by this project (it was added in 2.4).