Class NodeReference
java.lang.Object
org.eclipse.parsson.NodeReference
- Direct Known Subclasses:
NodeReference.ArrayReference, NodeReference.ObjectReference, NodeReference.RootReference
This class is a helper class for JsonPointer implementation,
and is not part of the API.
This class encapsulates a reference to a JSON node.
There are three types of references.
- a reference to the root of a JSON tree.
- a reference to a name/value (possibly non-existing) pair of a JSON object, identified by a name.
- a reference to a member value of a JSON array, identified by an index.
A referenced value can be retrieved or replaced. The value of a JSON object or JSON array can be removed. A new value can be added to a JSON object or inserted into a JSON array
Since a JsonObject or JsonArray is immutable, these operations
must not modify the referenced JSON object or array. The methods add(JsonValue),
replace(JsonValue), and remove() returns a new
JSON object or array after the execution of the operation.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static class(package private) static class(package private) static class -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract jakarta.json.JsonStructureadd(jakarta.json.JsonValue value) Add or replace a value at the referenced location.abstract booleancontains()Returntrueif a reference points to a valid value,falseotherwise.abstract jakarta.json.JsonValueget()Get the value at the referenced location.(package private) static NodeReferenceof(jakarta.json.JsonArray array, int index, JsonContext jsonContext) Returns aNodeReferencefor a member value in a JSON array.(package private) static NodeReferenceof(jakarta.json.JsonObject object, String name, JsonContext jsonContext) Returns aNodeReferencefor a name/value pair in a JSON object.(package private) static NodeReferenceof(jakarta.json.JsonStructure structure) Returns aNodeReferencefor aJsonStructure.abstract jakarta.json.JsonStructureremove()Remove the name/value pair from the JSON object, or the value in a JSON array, as specified by the referenceabstract jakarta.json.JsonStructurereplace(jakarta.json.JsonValue value) Replace the referenced value with the specified value.
-
Constructor Details
-
NodeReference
NodeReference()
-
-
Method Details
-
contains
public abstract boolean contains()Returntrueif a reference points to a valid value,falseotherwise.- Returns:
trueif a reference points to a value
-
get
public abstract jakarta.json.JsonValue get()Get the value at the referenced location.- Returns:
- the JSON value referenced
- Throws:
jakarta.json.JsonException- if the referenced value does not exist
-
add
public abstract jakarta.json.JsonStructure add(jakarta.json.JsonValue value) Add or replace a value at the referenced location. If the reference is the root of a JSON tree, the added value must be a JSON object or array, which becomes the referenced JSON value. If the reference is an index of a JSON array, the value is inserted into the array at the index. If the index is -1, the value is appended to the array. If the reference is a name of a JSON object, the name/value pair is added to the object, replacing any pair with the same name.- Parameters:
value- the value to be added- Returns:
- the JsonStructure after the operation
- Throws:
jakarta.json.JsonException- if the index to the array is not -1 or is out of range
-
remove
public abstract jakarta.json.JsonStructure remove()Remove the name/value pair from the JSON object, or the value in a JSON array, as specified by the reference- Returns:
- the JsonStructure after the operation
- Throws:
jakarta.json.JsonException- if the name/value pair of the referenced JSON object does not exist, or if the index of the referenced JSON array is out of range, or if the reference is a root reference
-
replace
public abstract jakarta.json.JsonStructure replace(jakarta.json.JsonValue value) Replace the referenced value with the specified value.- Parameters:
value- the JSON value to be stored at the referenced location- Returns:
- the JsonStructure after the operation
- Throws:
jakarta.json.JsonException- if the name/value pair of the referenced JSON object does not exist, or if the index of the referenced JSON array is out of range, or if the reference is a root reference
-
of
Returns aNodeReferencefor aJsonStructure.- Parameters:
structure- theJsonStructurereferenced- Returns:
- the
NodeReference
-
of
Returns aNodeReferencefor a name/value pair in a JSON object.- Parameters:
object- the referenced JSON objectname- the name of the name/pair- Returns:
- the
NodeReference
-
of
Returns aNodeReferencefor a member value in a JSON array.- Parameters:
array- the referenced JSON arrayindex- the index of the member value in the JSON array- Returns:
- the
NodeReference
-