You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Jackson 2.x has methods like JsonNode.asBoolean() to allow some additional coercions from types not directly compatible (boolean only assignable from JSON Booleans):
asBoolean() similar to booleanValue() but allows coercion from (compatible) String, as well as null and integer numbers. But if not, throw exception
asBooleanOpt() like asBoolean() but returns Optional<Boolean>, either present (as per asBoolean()) or absent (instead of exception)
but as with JsonNode.xxxValue() methods like booleanValue(), no exception is thrown but quietly default value (like false for boolean) is returned. For Jackson 3.0 we have unchecked JsonNodeException so let's use that instead.
We can also clarify coercions that are allowed, as well as extend set of asXxx() methods as it makes sense.
Relevant types/methods:
asBoolean()
asString()
Do we need to add any more?
asBinary()?
The text was updated successfully, but these errors were encountered:
cowtowncoder
changed the title
Extend, improve set of JsonNode.asXxx() methods for non-number types
Extend, improve set of JsonNode.asXxx() methods for non-number types (Boolean, String)
Mar 21, 2025
(note: similar to #5003 but for non-numbers)
Jackson 2.x has methods like
JsonNode.asBoolean()
to allow some additional coercions from types not directly compatible (boolean
only assignable from JSON Booleans):asBoolean()
similar tobooleanValue()
but allows coercion from (compatible)String
, as well as null and integer numbers. But if not, throw exceptionasBooleanOpt()
likeasBoolean()
but returnsOptional<Boolean>
, either present (as perasBoolean()
) or absent (instead of exception)but as with
JsonNode.xxxValue()
methods likebooleanValue()
, no exception is thrown but quietly default value (likefalse
forboolean
) is returned. For Jackson 3.0 we have uncheckedJsonNodeException
so let's use that instead.We can also clarify coercions that are allowed, as well as extend set of
asXxx()
methods as it makes sense.Relevant types/methods:
asBoolean()
asString()
Do we need to add any more?
asBinary()
?The text was updated successfully, but these errors were encountered: