Class JsonPointer
Map/List tree (such as the MarshalledMap/MarshalledList family).
A JSON Pointer is a string of zero or more
Example:
JsonMap
Notes:
- This class is not thread safe.
- Read-miss (missing key, out-of-range index, or type mismatch) resolves to
null viaeval(Object).
Beta — API subject to change: This type is part of the next-generation typed tree model layered over the
Marshalled* collections and may change incompatibly in a future release.
-
Method Summary
Modifier and TypeMethodDescriptionstatic StringdecodeToken(String token) Decodes an RFC 6901 reference token into a raw object member name (unescapes~1 to/ then~0 to~ ).static StringencodeToken(String rawMemberName) Encodes a raw object member name into an RFC 6901 reference token (escapes~ to~0 and/ to~1 ).Reads the value addressed by this pointer from the specified root.static JsonPointerParses and validates the specified RFC 6901 JSON Pointer string.Removes the member or element addressed by this pointer.Writes the specified value at the location addressed by this pointer, auto-vivifying missing intermediate containers.toString()
-
Method Details
-
of
Parses and validates the specified RFC 6901 JSON Pointer string.- Parameters:
pointer- The pointer string. The empty string references the whole document; a non-empty pointer must begin with/ .- Returns:
- A new
JsonPointer, nevernull . - Throws:
IllegalArgumentException- If the pointer isnull or malformed (non-empty and not beginning with/ ).
-
encodeToken
Encodes a raw object member name into an RFC 6901 reference token (escapes~ to~0 and/ to~1 ).- Parameters:
rawMemberName- The raw member name. Must not benull .- Returns:
- The encoded reference token.
-
decodeToken
Decodes an RFC 6901 reference token into a raw object member name (unescapes~1 to/ then~0 to~ ).- Parameters:
token- The reference token. Must not benull .- Returns:
- The decoded member name.
-
eval
Reads the value addressed by this pointer from the specified root.Walks the tokens from
root (which may be aMap/Listsuch as theMarshalledMap/MarshalledListfamily). The empty pointer returnsroot .- Parameters:
root- The root document. Can benull (treated as an empty document; the addressed value evaluates tonull ).- Returns:
- The addressed value, or
null on any missing key, out-of-range index, or type mismatch.
-
set
Writes the specified value at the location addressed by this pointer, auto-vivifying missing intermediate containers.Intermediate containers are created based on the next token: a numeric or
- token implies aJsonList, otherwise aJsonMap. The- token on a list appends. The empty pointer cannot mutateroot in place for the whole-document case, so it simply returnsvalue as the new root. -
remove
Removes the member or element addressed by this pointer.- Parameters:
root- The root document. Can benull (treated as an empty document — nothing is found to remove).- Returns:
- The removed value, or
null if the addressed member/element was absent (or the pointer is the root pointer).
-
toString
-