- java.lang.Object
-
- org.glassfish.json.JsonPointerImpl
-
- All Implemented Interfaces:
JsonPointer,Serializable
public final class JsonPointerImpl extends Object implements JsonPointer, Serializable
This class is an immutable representation of a JSON Pointer as specified in RFC 6901.
A JSON Pointer, when applied to a target
JsonValue, defines a reference location in the target.An empty JSON Pointer string defines a reference to the target itself.
If the JSON Pointer string is non-empty, it must be a sequence of '/' prefixed tokens, and the target must either be a
JsonArrayorJsonObject. If the target is aJsonArray, the pointer defines a reference to an array element, and the last token specifies the index. If the target is aJsonObject, the pointer defines a reference to a name/value pair, and the last token specifies the name.The method
getValue()returns the referenced value. The methodsadd(),replace(), andremove()executes the operations specified in RFC 6902.- Since:
- 1.1
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description JsonPointerImpl(String jsonPointer)Constructs and initializes a JsonPointerImpl.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description JsonStructureadd(JsonStructure target, JsonValue value)Adds or replaces a value at the referenced location in the specifiedtargetwith the specifiedvalue.booleancontainsValue(JsonStructure target)Returnstrueif there is a value at the referenced location in the specifiedtarget.booleanequals(Object obj)Compares thisJsonPointerwith another object.JsonValuegetValue(JsonStructure target)Returns the value at the referenced location in the specifiedtargetinthashCode()Returns the hash code value for thisJsonPointerobject.JsonStructureremove(JsonStructure target)Removes the value at the reference location in the specifiedtargetJsonStructurereplace(JsonStructure target, JsonValue value)Replaces the value at the referenced location in the specifiedtargetwith the specifiedvalue.StringtoString()Returns the string representation of this JSON Pointer.
-
-
-
Constructor Detail
-
JsonPointerImpl
public JsonPointerImpl(String jsonPointer)
Constructs and initializes a JsonPointerImpl.- Parameters:
jsonPointer- the JSON Pointer string- Throws:
NullPointerException- ifjsonPointerisnullJsonException- ifjsonPointeris not a valid JSON Pointer
-
-
Method Detail
-
equals
public boolean equals(Object obj)
Compares thisJsonPointerwith another object.
-
hashCode
public int hashCode()
Returns the hash code value for thisJsonPointerobject. The hash code of this object is defined by the hash codes of it's reference tokens.
-
containsValue
public boolean containsValue(JsonStructure target)
Returnstrueif there is a value at the referenced location in the specifiedtarget.- Specified by:
containsValuein interfaceJsonPointer- Parameters:
target- the target referenced by thisJsonPointer- Returns:
trueif this pointer points to a value in a specifiedtarget.
-
getValue
public JsonValue getValue(JsonStructure target)
Returns the value at the referenced location in the specifiedtarget- Specified by:
getValuein interfaceJsonPointer- Parameters:
target- the target referenced by thisJsonPointer- Returns:
- the referenced value in the target.
- Throws:
NullPointerException- iftargetis nullJsonException- if the referenced value does not exist
-
add
public JsonStructure add(JsonStructure target, JsonValue value)
Adds or replaces a value at the referenced location in the specifiedtargetwith the specifiedvalue.- If the reference is the target (empty JSON Pointer string),
the specified
value, which must be the same type as specifiedtarget, is returned. - If the reference is an array element, the specified
valueis inserted into the array, at the referenced index. The value currently at that location, and any subsequent values, are shifted to the right (adds one to the indices). Index starts with 0. If the reference is specified with a "-", or if the index is equal to the size of the array, the value is appended to the array. - If the reference is a name/value pair of a
JsonObject, and the referenced value exists, the value is replaced by the specifiedvalue. If the value does not exist, a new name/value pair is added to the object.
- Specified by:
addin interfaceJsonPointer- Parameters:
target- the target referenced by thisJsonPointervalue- the value to be added- Returns:
- the transformed
targetafter the value is added. - Throws:
NullPointerException- iftargetisnullJsonException- if the reference is an array element and the index is out of range (index < 0 || index > array size), or if the pointer contains references to non-existing objects or arrays.
- If the reference is the target (empty JSON Pointer string),
the specified
-
replace
public JsonStructure replace(JsonStructure target, JsonValue value)
Replaces the value at the referenced location in the specifiedtargetwith the specifiedvalue.- Specified by:
replacein interfaceJsonPointer- Parameters:
target- the target referenced by thisJsonPointervalue- the value to be stored at the referenced location- Returns:
- the transformed
targetafter the value is replaced. - Throws:
NullPointerException- iftargetisnullJsonException- if the referenced value does not exist, or if the reference is the target.
-
remove
public JsonStructure remove(JsonStructure target)
Removes the value at the reference location in the specifiedtarget- Specified by:
removein interfaceJsonPointer- Parameters:
target- the target referenced by thisJsonPointer- Returns:
- the transformed
targetafter the value is removed. - Throws:
NullPointerException- iftargetisnullJsonException- if the referenced value does not exist, or if the reference is the target.
-
toString
public String toString()
Returns the string representation of this JSON Pointer. The value to be returned is an empty string or a sequence of '/' prefixed tokens.- Specified by:
toStringin interfaceJsonPointer- Overrides:
toStringin classObject- Returns:
- the valid escaped JSON Pointer string.
-
-