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 MutableJsonPointerappend(int arrayIndex)Append a reference token.MutableJsonPointerappend(String referenceToken)Append a reference token.MutableJsonPointerappend(String referenceToken, boolean doEscape)Append a reference token.static Stringescape(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.MutableJsonPointerremove()Remove the last reference token from the end.StringtoString()static Stringunescape(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- AMutableJsonPointerinstance from which reference tokens are copied.
 
- 
MutableJsonPointer
public MutableJsonPointer(String pointer)
A constructor that receives a JSON pointer.- Parameters:
 pointer- A JSON pointer. Bothnulland an empty string are accepted. They represent the whole JSON document. In other cases,pointermust start with"/".- Throws:
 IllegalArgumentException-pointerdoes not start with"/"although it is neithernullnor 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-trueto make this method escape special characters inreferenceTokenbefore the reference token is appended. Theescape(String)method is used for the escape processing.- Returns:
 thisobject.
 
- 
append
public MutableJsonPointer append(String referenceToken)
Append a reference token.This method is an alias of
append(referenceToken, true). Special characters inreferenceTokenare escaped.- Parameters:
 referenceToken- A reference token to append.- Returns:
 thisobject.
 
- 
append
public MutableJsonPointer append(int arrayIndex)
Append a reference token.- Parameters:
 arrayIndex- A reference token.- Returns:
 thisobject.- Throws:
 IllegalArgumentException-arrayIndexis 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:
 thisobject.
 
- 
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,nullis 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,nullis returned. 
 
 - 
 
 -