Add "required" methods in JsonNode
: required(String | int)
, requiredAt(JsonPointer)
#2237
Milestone
JsonNode
: required(String | int)
, requiredAt(JsonPointer)
#2237
As per ideas on https://github.com/FasterXML/jackson-future-ideas/wiki/Jackson3-Changes---JsonNode it seems we could add couple of new, useful "validating" accessor methods, similar to how many other Java JSON libraries mandate presence of value when using accessors.
Here's a suggested list:
required(locator)
: similar toget(locator)
andpath(locator)
but will throw exception (instead of returningnull
orMissingNode
) with message indicating locatorlocator
is either property name (for Objects) or int index (for Arrays), same as with other accessorsJsonNode
at location, guaranteed not to benull
orMissingNode
requiredAt(jsonPointer)
(eitherString
or pre-compiledJsonPointer
)require()
: verify that node is NOTmissingNode
; if it is, throw same exception as previous accessors wouldroot.required("foo")
would be equivalent toroot.path("foo").require()
(except for slightly different error message)this
requireNonNull()
: similarly torequire()
, but also throw exception if "this" isNullNode
(returnstrue
forisNull()
)So: these could improve
JsonNode
ergonomics a lot.There are obviously many more we could consider (for example, whole set of
requireInt()
or such), but I think incremental improvements are a good way to go here.The text was updated successfully, but these errors were encountered: