ArrayNode.get() I'm accessing a null value or I'm out of bound? #4951
-
How can I distinguish if I'm accessing a null element or the index is out of bound? What's the reason why ArrayNode.get() returns null on out of bound index? jackson-databind/src/main/java/tools/jackson/databind/node/ArrayNode.java Lines 221 to 226 in 961c128 |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Null elements are represented as non-null Or, if you don't want null checks,
As to why |
Beta Was this translation helpful? Give feedback.
Null elements are represented as non-null
NullNode
s, soJsonNode.isNull()
.Or, if you don't want null checks,
ArrayNode.path(int)
never returnsnull
but returns:NullNode
if within Array value, JSONnull
valueMissingNode
if outside array (index out-of-bounds)As to why
null
: design choice, to work similar toObjectNode.get(String)
for key that does not match any property; returnsnull
.