Class NodePointer
Node
values.
A parsed JSON pointer can get a value from a Node by pointer and perform JSON-patch like operations like adding a value to a specific pointer target.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionAdds or replaces avalue
incontainer
at the JSON pointer location.addWithIntermediateValues
(Node container, Node value) Adds or replaces avalue
incontainer
at the JSON pointer location.static NodePointer
empty()
Gets an empty Node pointer.boolean
static NodePointer
Creates a NodePointer from a Node value.getParts()
Gets the parsed parts of the pointer.Gets a value from a container shape at the pointer location.int
hashCode()
static NodePointer
Parses a JSON pointer.toString()
static String
Unescapes special JSON pointer cases.
-
Method Details
-
empty
Gets an empty Node pointer.- Returns:
- Returns a node pointer with a value of "".
-
fromNode
Creates a NodePointer from a Node value.- Parameters:
node
- Node value to parse.- Returns:
- Returns the parsed NodePointer.
- Throws:
ExpectationNotMetException
- if the pointer cannot be parsed.
-
unescape
Unescapes special JSON pointer cases.- Parameters:
pointerPart
- Pointer to unescape.- Returns:
- Returns the unescaped pointer.
-
parse
Parses a JSON pointer.A JSON pointer that starts with "#/" is treated as "/". JSON pointers must start with "#/" or "/" to be parsed correctly.
- Parameters:
pointer
- JSON pointer to parse.- Returns:
- Returns the parsed pointer.
- Throws:
IllegalArgumentException
- if the pointer does not start with slash (/).
-
getParts
Gets the parsed parts of the pointer.- Returns:
- Returns the immutable pointer parts.
-
toString
-
equals
-
hashCode
public int hashCode() -
getValue
Gets a value from a container shape at the pointer location.When the pointer is "", then provided value is returned. When the pointer is "/", a root object key value of "" is returned. When an invalid property or array index is accessed, a
NullNode
is returned. "-" can be used to access the last element of an array. Any error like accessing an object key from an array or attempting to access an invalid array index will return aNullNode
.- Parameters:
container
- Node value container to extract a value from.- Returns:
- Returns the extracted value or a
NullNode
if not found.
-
addValue
Adds or replaces avalue
incontainer
at the JSON pointer location.When the JSON pointer is "", the entire document is replaced with the given
value
. "-" can be used to access the last element of an array or to add an element to the end of an array. Any error like adding an object key to an array or attempting to access an invalid array segment will log a warning and return the given value as-is.- Parameters:
container
- Node to update.value
- Value to update or replace.- Returns:
- Returns a representation of
container
with the updated value.
-
addWithIntermediateValues
Adds or replaces avalue
incontainer
at the JSON pointer location.When the JSON pointer is "", the entire document is replaced with the given
value
. "-" can be used to access the last element of an array or to add an element to the end of an array. UnlikeaddValue(Node, Node)
, attempting to add a property to a non-existent object will create a new object and continue adding to the created result.- Parameters:
container
- Node to update.value
- Value to update or replace.- Returns:
- Returns a representation of
container
with the updated value.
-