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
{{ message }}
Repository navigation
Add "required" methods in JsonNode: required(String | int), requiredAt(JsonPointer)Â #2237
required(locator): similar to get(locator) and path(locator) but will throw exception (instead of returning null or MissingNode) with message indicating locator
locator is either property name (for Objects) or int index (for Arrays), same as with other accessors
Returns JsonNode at location, guaranteed not to be null or MissingNode
Exception to throw needs to be unchecked exception, even for 2.10 (in 3.0 we will likely change all Jackson exceptions to be unchecked) -- partly since we do not have access to context with any of the accessors
requiredAt(jsonPointer) (either String or pre-compiled JsonPointer)
same as above, but allows convenient single-call verificatiion
require(): verify that node is NOT missingNode; if it is, throw same exception as previous accessors would
essentially, root.required("foo") would be equivalent to root.path("foo").require() (except for slightly different error message)
returns this
requireNonNull(): similarly to require(), but also throw exception if "this" is NullNode (returns true for isNull())
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.
Methods added as suggested: for 2.x (at least), failure indicated by IllegalArgumentException: for 3.x will change to new unchecked Jackson-specific exceptions.
Activity
Fix #2237
cowtowncoder commentedon Aug 29, 2019
Methods added as suggested: for 2.x (at least), failure indicated by
IllegalArgumentException: for 3.x will change to new unchecked Jackson-specific exceptions.Improve javadocs wrt #2237