Package com.authlete.common.util
Class MutableJsonPointer
- java.lang.Object
-
- com.authlete.common.util.MutableJsonPointer
-
public class MutableJsonPointer extends Object
Mutable JSON Pointer.// From a string. MutableJsonPointer pointer = new MutableJsonPointer("/a/b"); // Append one by one. MutableJsonPointer pointer = new MutableJsonPointer().append("a").append("b"); // Modify. MutableJsonPointer pointer = new MutableJsonPointer("/a/c").remove().append("b"); // Get reference tokens. List<String> tokens = new MutableJsonPointer("/a/b").getReferenceTokens(); // Create a JsonPointer instance from a MutableJsonPointer instance. JsonPointer pointer = Json.createPointer(new MutableJsonPointer("/a/b").toString());
- Since:
- 3.17
- See Also:
- RFC 6901: JavaScript Object Notation (JSON) Pointer, Jakarta JSON Processing
-
-
Constructor Summary
Constructors Constructor Description MutableJsonPointer()
The default constructor.MutableJsonPointer(MutableJsonPointer pointer)
A copy constructor.MutableJsonPointer(String pointer)
A constructor that receives a JSON pointer.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description MutableJsonPointer
append(int arrayIndex)
Append a reference token.MutableJsonPointer
append(String referenceToken)
Append a reference token.MutableJsonPointer
append(String referenceToken, boolean doEscape)
Append a reference token.static String
escape(String input)
Escape special characters in the given string according to the rules defined in the Section 3.List<String>
getReferenceTokens()
Get the list of reference tokens.MutableJsonPointer
remove()
Remove the last reference token from the end.String
toString()
static String
unescape(String input)
Unescape special sequences in the given string according to the rules defined in the Section 4.
-
-
-
Constructor Detail
-
MutableJsonPointer
public MutableJsonPointer()
The default constructor.
-
MutableJsonPointer
public MutableJsonPointer(MutableJsonPointer pointer)
A copy constructor.- Parameters:
pointer
- AMutableJsonPointer
instance from which reference tokens are copied.
-
MutableJsonPointer
public MutableJsonPointer(String pointer)
A constructor that receives a JSON pointer.- Parameters:
pointer
- A JSON pointer. Bothnull
and an empty string are accepted. They represent the whole JSON document. In other cases,pointer
must start with"/"
.- Throws:
IllegalArgumentException
-pointer
does not start with"/"
although it is neithernull
nor an empty string.
-
-
Method Detail
-
append
public MutableJsonPointer append(String referenceToken, boolean doEscape)
Append a reference token.- Parameters:
referenceToken
- A reference token to append.doEscape
-true
to make this method escape special characters inreferenceToken
before the reference token is appended. Theescape(String)
method is used for the escape processing.- Returns:
this
object.
-
append
public MutableJsonPointer append(String referenceToken)
Append a reference token.This method is an alias of
append
(referenceToken, true)
. Special characters inreferenceToken
are escaped.- Parameters:
referenceToken
- A reference token to append.- Returns:
this
object.
-
append
public MutableJsonPointer append(int arrayIndex)
Append a reference token.- Parameters:
arrayIndex
- A reference token.- Returns:
this
object.- Throws:
IllegalArgumentException
-arrayIndex
is less than 0.
-
remove
public MutableJsonPointer remove()
Remove the last reference token from the end.Even if this method is called more times than the number of reference tokens held by this instance, no exception is thrown.
- Returns:
this
object.
-
getReferenceTokens
public List<String> getReferenceTokens()
Get the list of reference tokens.- Returns:
- The list of reference tokens.
-
escape
public static String escape(String input)
Escape special characters in the given string according to the rules defined in the Section 3. Syntax of RFC 6901 JavaScript Object Notation (JSON) Pointer.To be concrete, all
"~"
are converted to"~0"
and then all"/"
are converted to"~1"
.- Parameters:
input
- A string that may contain special characters ("~"
and"/"
).- Returns:
- A new string after conversion. If the given string is
null
,null
is returned.
-
unescape
public static String unescape(String input)
Unescape special sequences in the given string according to the rules defined in the Section 4. Evaluation of RFC 6901 JavaScript Object Notation (JSON) Pointer.To be concrete, all
"~1"
are converted to"/"
and then all"~0"
are converted to"~"
.- Parameters:
input
- A string that may contain special sequences ("~0"
and"~1"
).- Returns:
- A new string after conversion. If the given string is
null
,null
is returned.
-
-