public final class JsonPointer extends Object
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 JsonArray
or JsonObject
. If the target is a JsonArray
, the pointer
defines a reference to an array element, and the last token specifies the index.
If the target is a JsonObject
, 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 methods add()
, replace()
,
and remove()
executes the operations specified in
RFC 6902.
Constructor and Description |
---|
JsonPointer(String jsonPointer)
Constructs and initializes a JsonPointer.
|
Modifier and Type | Method and Description |
---|---|
JsonArray |
add(JsonArray target,
JsonValue value)
Adds or replaces a value at the referenced location in the specified
target with the specified value . |
JsonObject |
add(JsonObject target,
JsonValue value)
Adds or replaces a value at the referenced location in the specified
target with the specified value . |
JsonStructure |
add(JsonStructure target,
JsonValue value)
Adds or replaces a value at the referenced location in the specified
target with the specified value . |
boolean |
equals(Object obj)
Compares this
JsonPointer with another object. |
JsonValue |
getValue(JsonStructure target)
Returns the value at the referenced location in the specified
target |
int |
hashCode()
Returns the hash code value for this
JsonPointer object. |
JsonArray |
remove(JsonArray target)
Removes the value at the reference location in the specified
target |
JsonObject |
remove(JsonObject target)
Removes the value at the reference location in the specified
target |
JsonStructure |
remove(JsonStructure target)
Removes the value at the reference location in the specified
target |
JsonArray |
replace(JsonArray target,
JsonValue value)
Replaces the value at the referenced location in the specified
|
JsonObject |
replace(JsonObject target,
JsonValue value)
Replaces the value at the referenced location in the specified
|
JsonStructure |
replace(JsonStructure target,
JsonValue value)
Replaces the value at the referenced location in the specified
target with the specified value . |
public JsonPointer(String jsonPointer)
jsonPointer
- the JSON Pointer stringNullPointerException
- if jsonPointer
is null
JsonException
- if jsonPointer
is not a valid JSON Pointerpublic boolean equals(Object obj)
JsonPointer
with another object.public int hashCode()
JsonPointer
object.
The hash code of this object is defined by the hash codes of it's reference tokens.public JsonValue getValue(JsonStructure target)
target
target
- the target referenced by this JsonPointer
NullPointerException
- if target
is nullJsonException
- if the referenced value does not existpublic JsonStructure add(JsonStructure target, JsonValue value)
target
with the specified value
.
value
, which must be the same type as
specified target
, is returned.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.JsonObject
, and the
referenced value exists, the value is replaced by the specified value
.
If the value does not exist, a new name/value pair is added to the object.target
- the target referenced by this JsonPointer
value
- the value to be addedtarget
after the value is added.NullPointerException
- if target
is null
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.public JsonStructure replace(JsonStructure target, JsonValue value)
target
with the specified value
.target
- the target referenced by this JsonPointer
value
- the value to be stored at the referenced locationtarget
after the value is replaced.NullPointerException
- if target
is null
JsonException
- if the referenced value does not exist,
or if the reference is the target.public JsonStructure remove(JsonStructure target)
target
target
- the target referenced by this JsonPointer
target
after the value is removed.NullPointerException
- if target
is null
JsonException
- if the referenced value does not exist,
or if the reference is the target.public JsonObject add(JsonObject target, JsonValue value)
target
with the specified value
.target
- the target referenced by this JsonPointer
value
- the value to be addedtarget
after the value is added.NullPointerException
- if target
is null
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.add(JsonStructure, JsonValue)
public JsonArray add(JsonArray target, JsonValue value)
target
with the specified value
.target
- the target referenced by this JsonPointer
value
- the value to be addedtarget
after the value is added.NullPointerException
- if target
is null
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.add(JsonStructure, JsonValue)
public JsonObject replace(JsonObject target, JsonValue value)
target
- the target referenced by this JsonPointer
value
- the value to be stored at the referenced locationtarget
after the value is replaced.NullPointerException
- if target
is null
JsonException
- if the referenced value does not exist,
or if the reference is the target.
target
with the specified value
.replace(JsonStructure, JsonValue)
public JsonArray replace(JsonArray target, JsonValue value)
target
- the target referenced by this JsonPointer
value
- the value to be stored at the referenced locationtarget
after the value is replaced.NullPointerException
- if target
is null
JsonException
- if the referenced value does not exist,
or if the reference is the target.
target
with the specified value
.replace(JsonStructure, JsonValue)
public JsonObject remove(JsonObject target)
target
target
- the target referenced by this JsonPointer
target
after the value is removed.NullPointerException
- if target
is null
JsonException
- if the referenced value does not exist,
or if the reference is the target.remove(JsonStructure)
public JsonArray remove(JsonArray target)
target
target
- the target referenced by this JsonPointer
target
after the value is removed.NullPointerException
- if target
is null
JsonException
- if the referenced value does not exist,
or if the reference is the target.remove(JsonStructure)
Copyright © 2012-2015, Oracle and/or its affiliates. All Rights Reserved. Use is subject to license terms.
Comments to : [email protected]