-
public interface JsonPointer
This interface represents an immutable implementation of a JSON Pointer as defined by 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
JsonArray
orJsonObject
. 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. Methodsadd()
,replace()
, andremove()
execute operations specified in RFC 6902.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description <T extends JsonStructure>
Tadd(T target, JsonValue value)
Adds or replaces a value at the referenced location in the specifiedtarget
with the specifiedvalue
.boolean
containsValue(JsonStructure target)
Returnstrue
if there is a value at the referenced location in the specifiedtarget
.JsonValue
getValue(JsonStructure target)
Returns the value at the referenced location in the specifiedtarget
.<T extends JsonStructure>
Tremove(T target)
Removes the value at the reference location in the specifiedtarget
.<T extends JsonStructure>
Treplace(T target, JsonValue value)
Replaces the value at the referenced location in the specifiedtarget
with the specifiedvalue
.String
toString()
Returns the string representation of this JSON Pointer.
-
-
-
Method Detail
-
add
<T extends JsonStructure> T add(T target, JsonValue value)
Adds or replaces a value at the referenced location in the specifiedtarget
with 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
value
is 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.
- Type Parameters:
T
- the target type, must be a subtype ofJsonValue
- Parameters:
target
- the target referenced by thisJsonPointer
value
- the value to be added- Returns:
- the transformed
target
after the value is added. - Throws:
NullPointerException
- iftarget
isnull
JsonException
- 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
-
remove
<T extends JsonStructure> T remove(T target)
Removes the value at the reference location in the specifiedtarget
.- Type Parameters:
T
- the target type, must be a subtype ofJsonValue
- Parameters:
target
- the target referenced by thisJsonPointer
- Returns:
- the transformed
target
after the value is removed. - Throws:
NullPointerException
- iftarget
isnull
JsonException
- if the referenced value does not exist, or if the reference is the target.
-
replace
<T extends JsonStructure> T replace(T target, JsonValue value)
Replaces the value at the referenced location in the specifiedtarget
with the specifiedvalue
.- Type Parameters:
T
- the target type, must be a subtype ofJsonValue
- Parameters:
target
- the target referenced by thisJsonPointer
value
- the value to be stored at the referenced location- Returns:
- the transformed
target
after the value is replaced. - Throws:
NullPointerException
- iftarget
isnull
JsonException
- if the referenced value does not exist, or if the reference is the target.
-
containsValue
boolean containsValue(JsonStructure target)
Returnstrue
if there is a value at the referenced location in the specifiedtarget
.- Parameters:
target
- the target referenced by thisJsonPointer
- Returns:
true
if this pointer points to a value in a specifiedtarget
.
-
getValue
JsonValue getValue(JsonStructure target)
Returns the value at the referenced location in the specifiedtarget
.- Parameters:
target
- the target referenced by thisJsonPointer
- Returns:
- the referenced value in the target.
- Throws:
NullPointerException
- iftarget
is nullJsonException
- if the referenced value does not exist
-
-