Extend, improve set of JsonNode.asXxx()
methods for non-number types (Boolean, String)
#5034
Labels
Milestone
(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: