|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.eel.kitchen.util.JsonPointer
public final class JsonPointer
Implementation of IETF JSON Pointer draft, version 1
JSON Pointer is a draft standard defining a way to address paths within JSON documents. Paths apply to container objects, ie arrays or nodes. For objects, path elements are property names. For arrays, they are the index in the array.
The general syntax is #/path/elements/here. A path element is
referred to as a "reference token" in the specification.
JSON Pointers are always absolute: it is perfectly legal, for
instance, to have properties named . and .. in a JSON
object.
Even / is a valid property name. For this reason,
the caret (^) has been chosen as an escape character, but only if
followed by itself or /. Therefore:
^/ becomes /,^^ becomes ^,^<anythingelse> is illegal.There are two pending traps with JSON Pointer which one must be aware of:
The initial input string MAY be JSON escaped (FIXME: pointer to spec)
; it means that, for instance,"#\/" and "#/" are the same string, since the first
version is "merely" the JSON escaped version of the first.The empty string is a valid property name in a JSON
object, which means # and #/ are different. The second
refers to property "" inside an object while the first refers
to the JSON document itself. Implied: implementations must handle
the case where the document is not an object (leading to a
"dangling" JSON Pointer).
Fortunately, Jackson makes both points easy to handle.
Final note: please note that all instances of this class are immutable.
| Field Summary | |
|---|---|
static JsonPointer |
ROOT
|
| Constructor Summary | |
|---|---|
JsonPointer(String input)
Constructor |
|
| Method Summary | |
|---|---|
JsonPointer |
append(int index)
Append an array index to this pointer. |
JsonPointer |
append(String element)
Append a path element to this pointer. |
boolean |
equals(Object obj)
|
List<String> |
getElements()
Return the reference tokens of this JSON Pointer, in order. |
JsonNode |
getPath(JsonNode node)
Resolve this JSON Pointer against a JSON instance |
int |
hashCode()
|
String |
toString()
|
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
public static final JsonPointer ROOT
| Constructor Detail |
|---|
public JsonPointer(String input)
throws JsonSchemaException
FIXME: unclear whether we should only accept #-prefixed inputs, therefore both are accepted
input - The input string, guaranteed not to be JSON encoded
JsonSchemaException - Illegal JSON Pointer| Method Detail |
|---|
public List<String> getElements()
Listpublic JsonPointer append(String element)
element - the element to append
public 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 add
public JsonNode getPath(JsonNode node)
node - the node to resolve against
MissingNodepublic boolean equals(Object obj)
equals in class Objectpublic int hashCode()
hashCode in class Objectpublic String toString()
toString in class Object
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||