Package org.glassfish.json
Class NodeReference
java.lang.Object
org.glassfish.json.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(javax.json.JsonValue)
,
replace(javax.json.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 JsonStructure
Add or replace a value at the referenced location.abstract boolean
contains()
Returntrue
if a reference points to a valid value,false
otherwise.abstract JsonValue
get()
Get the value at the referenced location.static NodeReference
Returns aNodeReference
for a member value in a JSON array.static NodeReference
of
(JsonObject object, String name) Returns aNodeReference
for a name/value pair in a JSON object.static NodeReference
of
(JsonStructure structure) Returns aNodeReference
for aJsonStructure
.abstract JsonStructure
remove()
Remove the name/value pair from the JSON object, or the value in a JSON array, as specified by the referenceabstract JsonStructure
Replace the referenced value with the specified value.
-
Constructor Details
-
NodeReference
NodeReference()
-
-
Method Details
-
contains
public abstract boolean contains()Returntrue
if a reference points to a valid value,false
otherwise.- Returns:
true
if a reference points to a value
-
get
Get the value at the referenced location.- Returns:
- the JSON value referenced
- Throws:
JsonException
- if the referenced value does not exist
-
add
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:
JsonException
- if the index to the array is not -1 or is out of range
-
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:
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
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:
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 aNodeReference
for aJsonStructure
.- Parameters:
structure
- theJsonStructure
referenced- Returns:
- the
NodeReference
-
of
Returns aNodeReference
for 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 aNodeReference
for 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
-