public final class JsonPointer extends JsonFragment
JSON Pointer is an IETF draft defining a way to address paths within JSON documents. Paths apply to containers, ie arrays or nodes. For objects, path elements are member names. For arrays, they are indices in the array (starting from 0).
The general syntax is #/path/elements/here
. A path element is
referred to as a "reference token" in the specification.
The difficulty solved by JSON Pointer is that any JSON String is valid as an object member name. These are all valid object member names, and all of them can be addressed by using JSON Pointer:
""
-- the empty string;"/"
;"0"
;"-1"
;"."
, ".."
, "../.."
.The latter example is the reason why a JSON Pointer is always absolute.
All instances of this class are thread safe and immutable.
asString
Constructor and Description |
---|
JsonPointer(String input)
Constructor
|
Modifier and Type | Method and Description |
---|---|
JsonPointer |
append(int index)
Append an array index to this pointer.
|
JsonPointer |
append(String element)
Append a path element to this pointer.
|
JsonNode |
resolve(JsonNode node)
Resolve this fragment against a given node
|
compareTo, equals, fromFragment, hashCode, isEmpty, toString
public JsonPointer(String input) throws JsonSchemaException
input
- The input string, guaranteed not to be JSON encodedJsonSchemaException
- Illegal JSON Pointerpublic JsonPointer append(String element)
element
- the element to appendpublic JsonPointer append(int index)
Note that the index validity is NOT checked for (ie,
you can append -1
if you want to -- don't do that)
index
- the index to addpublic JsonNode resolve(JsonNode node)
JsonFragment
resolve
in class JsonFragment
node
- the nodeMissingNode
if the fragment is not
found)Copyright © 2013. All Rights Reserved.