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.asInt() to allow some additional coercions from types not directly compatible (int only coercible from JSON Numbers):
asInt() similar to intValue() but allows coercion from (compatible) String, as well as null (and even Boolean?). But if not, throw exception
asIntOpt() like asInt() but returns OptionalInt, either present (as per asInt()) or absent (instead of exception)
but as with JsonNode.xxxValue() methods like intValue(), no exception is thrown but quietly default value (like 0 for int) is returned. For Jackson 3.0 we have unchecked JsonNodeException so use that instead.
We can also clarify coercions that are allowed, as well as extend set of asXxx() methods as it makes sense.
Types/methods to handle:
asDecimal() (BigDecimal)
asDouble()
asInt()
asLong()
but let's also add
asBigInteger()
(probably not asFloat() or asShort() or asByte())
The text was updated successfully, but these errors were encountered:
cowtowncoder
changed the title
Extend, improve set of JsonNode.asXxx() methods
Extend, improve set of JsonNode.asXxx() methods for number types
Mar 19, 2025
cowtowncoder
changed the title
Extend, improve set of JsonNode.asXxx() methods for number types
Extend, improve set of JsonNode.asXxx() methods for number types [JSTEP-3]
Mar 26, 2025
(note: continuation of #4958 and #4991 )
Jackson 2.x has methods like
JsonNode.asInt()
to allow some additional coercions from types not directly compatible (int
only coercible from JSON Numbers):asInt()
similar tointValue()
but allows coercion from (compatible)String
, as well as null (and even Boolean?). But if not, throw exceptionasIntOpt()
likeasInt()
but returnsOptionalInt
, either present (as perasInt()
) or absent (instead of exception)but as with
JsonNode.xxxValue()
methods likeintValue()
, no exception is thrown but quietly default value (like0
forint
) is returned. For Jackson 3.0 we have uncheckedJsonNodeException
so use that instead.We can also clarify coercions that are allowed, as well as extend set of
asXxx()
methods as it makes sense.Types/methods to handle:
asDecimal()
(BigDecimal
)asDouble()
asInt()
asLong()
but let's also add
asBigInteger()
(probably not
asFloat()
orasShort()
orasByte()
)The text was updated successfully, but these errors were encountered: