(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 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:
Do we need to add any more?
(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 (booleanonly 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 (likefalseforboolean) is returned. For Jackson 3.0 we have uncheckedJsonNodeExceptionso 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()?