@NotMutable @ThreadSafety(level=COMPLETELY_THREADSAFE) public final class JSONString extends JSONValue
\"
or \
u0022
.
\\
or \
u005C
.
\
u
,
like \
u0000
to represent the ASCII null character U+0000.
For certain characters, a more user-friendly escape sequence is also
defined:
\t
or
\
u0009
.
\n
or
\
u000A
.
\f
or
\
u000C
.
\r
or
\
u000D
.
\
u
prefix in front of each four-hexadecimal digit sequence in
the UTF-16 representation of that character. For example, the "LATIN SMALL
LETTER N WITH TILDE" character U+00F1 may be escaped as
\
u00F1
, while the "MUSICAL SYMBOL G CLEF" character U+1D11E
may be escaped as \
uD834
\
uDD1E
. And while
the forward slash character is not required to be escaped in JSON strings, it
can be escaped using \/
as a more human-readable alternative to
\
u002F
.
JSONString(String)
constructor should not
have any escaping performed, and the string returned by the
stringValue()
method will not have any escaping performed. These
methods work with the Java string that is represented by the JSON string.
toString()
method (or
appended to the buffer provided to the toString(StringBuilder)
method) will be the string representation used in the JSON object that was
parsed. Otherwise, this class will generate an appropriate string
representation, which will be surrounded by quotation marks and will have the
minimal required encoding applied.
toNormalizedString()
method (or appended
to the buffer provided to the toNormalizedString(StringBuilder)
method) will be generated by converting it to lowercase, surrounding it with
quotation marks, and using the \
u
-style escaping for all
characters other than the following (as contained in the LDAP printable
character set defined in RFC
4517 section 3.2, and indicated by the
StaticUtils.isPrintable(char)
method):
Constructor and Description |
---|
JSONString(java.lang.String value)
Creates a new JSON string.
|
Modifier and Type | Method and Description |
---|---|
void |
appendToJSONBuffer(JSONBuffer buffer)
Appends this value to the provided JSON buffer.
|
void |
appendToJSONBuffer(java.lang.String fieldName,
JSONBuffer buffer)
Appends a field with the given name and this value to the provided JSON
buffer.
|
boolean |
equals(JSONString s,
boolean ignoreCase)
Indicates whether the value of this JSON string matches that of the
provided string, optionally ignoring differences in capitalization.
|
boolean |
equals(JSONValue v,
boolean ignoreFieldNameCase,
boolean ignoreValueCase,
boolean ignoreArrayOrder)
Indicates whether this JSON value is considered equal to the provided JSON
value, subject to the specified constraints.
|
boolean |
equals(java.lang.Object o)
Indicates whether the provided object is equal to this JSON value.
|
int |
hashCode()
Retrieves a hash code for this JSON value.
|
java.lang.String |
stringValue()
Retrieves the string value for this object.
|
java.lang.String |
toNormalizedString()
Retrieves a normalized representation of this JSON string as it should
appear in a JSON object, including the surrounding quotes and any
appropriate escaping.
|
java.lang.String |
toNormalizedString(boolean ignoreFieldNameCase,
boolean ignoreValueCase,
boolean ignoreArrayOrder)
Retrieves a normalized representation of this JSON string as it should
appear in a JSON object, including the surrounding quotes and any
appropriate escaping.
|
void |
toNormalizedString(java.lang.StringBuilder buffer)
Appends a normalized representation of this JSON string as it should
appear in a JSON object, including the surrounding quotes and any
appropriate escaping, to the provided buffer.
|
void |
toNormalizedString(java.lang.StringBuilder buffer,
boolean ignoreFieldNameCase,
boolean ignoreValueCase,
boolean ignoreArrayOrder)
Appends a normalized representation of this JSON string as it should
appear in a JSON object, including the surrounding quotes and any
appropriate escaping, to the provided buffer.
|
JSONString |
toNormalizedValue(boolean ignoreFieldNameCase,
boolean ignoreValueCase,
boolean ignoreArrayOrder)
Retrieves a normalized representation of this value using the provided
settings.
|
java.lang.String |
toSingleLineString()
Retrieves a single-line representation of this JSON string as it should
appear in a JSON object, including the surrounding quotation marks and any
appropriate escaping.
|
void |
toSingleLineString(java.lang.StringBuilder buffer)
Appends a single-line string representation of this JSON string as it
should appear in a JSON object, including the surrounding quotation marks
and any appropriate escaping, to the provided buffer.
|
java.lang.String |
toString()
Retrieves a string representation of this JSON string as it should appear
in a JSON object, including the surrounding quotation marks and any
appropriate escaping To obtain the string to which this value refers
without the surrounding quotation marks or escaping, use the
stringValue() method. |
void |
toString(java.lang.StringBuilder buffer)
Appends a string representation of this JSON string as it should appear
in a JSON object, including the surrounding quotation marks and any
appropriate escaping, to the provided buffer.
|
public JSONString(@NotNull java.lang.String value)
value
- The string to represent in this JSON value. It must not be
null
.@NotNull public java.lang.String stringValue()
public int hashCode()
public boolean equals(@Nullable java.lang.Object o)
public boolean equals(@NotNull JSONString s, boolean ignoreCase)
s
- The JSON string to compare against this JSON string.
It must not be null
.ignoreCase
- Indicates whether to ignore differences in
capitalization.true
if the value of this JSON string matches the value of
the provided string (optionally ignoring differences in
capitalization), or false
if not.public boolean equals(@NotNull JSONValue v, boolean ignoreFieldNameCase, boolean ignoreValueCase, boolean ignoreArrayOrder)
equals
in class JSONValue
v
- The JSON value for which to make the
determination. It must not be null
.ignoreFieldNameCase
- Indicates whether to ignore differences in the
capitalization of JSON field names.ignoreValueCase
- Indicates whether to ignore differences in
the capitalization of JSON values that
represent strings.ignoreArrayOrder
- Indicates whether to ignore differences in the
order of elements in JSON arrays.true
if this JSON value is considered equal to the
provided JSON value (subject to the specified constraints), or
false
if not.@NotNull public java.lang.String toString()
stringValue()
method.
public void toString(@NotNull java.lang.StringBuilder buffer)
stringValue()
method.
@NotNull public java.lang.String toSingleLineString()
stringValue()
method.toSingleLineString
in class JSONValue
public void toSingleLineString(@NotNull java.lang.StringBuilder buffer)
stringValue()
method.toSingleLineString
in class JSONValue
buffer
- The buffer to which the information should be appended.@NotNull public java.lang.String toNormalizedString()
toNormalizedString
in class JSONValue
public void toNormalizedString(@NotNull java.lang.StringBuilder buffer)
toNormalizedString
in class JSONValue
buffer
- The buffer to which the information should be appended.@NotNull public java.lang.String toNormalizedString(boolean ignoreFieldNameCase, boolean ignoreValueCase, boolean ignoreArrayOrder)
ignoreValueCase
is
false
.toNormalizedString
in class JSONValue
ignoreFieldNameCase
- Indicates whether field names should be
treated in a case-sensitive (if false
)
or case-insensitive (if true
) manner.ignoreValueCase
- Indicates whether string field values should
be treated in a case-sensitive (if
false
) or case-insensitive (if
true
) manner.ignoreArrayOrder
- Indicates whether the order of elements in an
array should be considered significant (if
false
) or insignificant (if
true
).public void toNormalizedString(@NotNull java.lang.StringBuilder buffer, boolean ignoreFieldNameCase, boolean ignoreValueCase, boolean ignoreArrayOrder)
ignoreValueCase
is
false
.toNormalizedString
in class JSONValue
buffer
- The buffer to which the information should be
appended.ignoreFieldNameCase
- Indicates whether field names should be
treated in a case-sensitive (if false
)
or case-insensitive (if true
) manner.ignoreValueCase
- Indicates whether string field values should
be treated in a case-sensitive (if
false
) or case-insensitive (if
true
) manner.ignoreArrayOrder
- Indicates whether the order of elements in an
array should be considered significant (if
false
) or insignificant (if
true
).@NotNull public JSONString toNormalizedValue(boolean ignoreFieldNameCase, boolean ignoreValueCase, boolean ignoreArrayOrder)
toNormalizedValue
in class JSONValue
ignoreFieldNameCase
- Indicates whether field names should be
treated in a case-sensitive (if false
)
or case-insensitive (if true
) manner.ignoreValueCase
- Indicates whether string field values should
be treated in a case-sensitive (if
false
) or case-insensitive (if
true
) manner.ignoreArrayOrder
- Indicates whether the order of elements in an
array should be considered significant (if
false
) or insignificant (if
true
).public void appendToJSONBuffer(@NotNull JSONBuffer buffer)
appendToJSONBuffer
in class JSONValue
buffer
- The JSON buffer to which this value should be appended.public void appendToJSONBuffer(@NotNull java.lang.String fieldName, @NotNull JSONBuffer buffer)
appendToJSONBuffer
in class JSONValue
fieldName
- The name to use for the field.buffer
- The JSON buffer to which this value should be appended.