Package com.unboundid.util.json
Class JSONValue
- java.lang.Object
-
- com.unboundid.util.json.JSONValue
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.Comparable<JSONValue>
- Direct Known Subclasses:
JSONArray,JSONBoolean,JSONNull,JSONNumber,JSONObject,JSONString
@NotExtensible @ThreadSafety(level=INTERFACE_THREADSAFE) public abstract class JSONValue extends java.lang.Object implements java.io.Serializable, java.lang.Comparable<JSONValue>
This class provides the base class for data types that can be used as values in JSON objects and as elements in JSON arrays. The types of values defined in the ECMA-404 specification are:-
The
nullvalue, as implemented in theJSONNullclass. -
The Boolean
trueandfalsevalues, as implemented in theJSONBooleanclass. -
Numeric values, as implemented in the
JSONNumberclass. -
String values, as implemented in the
JSONStringclass. -
Object values (consisting of zero or more name-value pairs), as
implemented in the
JSONObjectclass. -
Arrays of JSON values, as implemented in the
JSONArrayclass.
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description JSONValue()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract voidappendToJSONBuffer(JSONBuffer buffer)Appends this value to the provided JSON buffer.abstract voidappendToJSONBuffer(java.lang.String fieldName, JSONBuffer buffer)Appends a field with the given name and this value to the provided JSON buffer.intcompareTo(JSONValue value)Compares the provided value to this value to determine their relative order in a sorted list.abstract booleanequals(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.abstract booleanequals(java.lang.Object o)Indicates whether the provided object is equal to this JSON value.abstract inthashCode()Retrieves a hash code for this JSON value.abstract java.lang.StringtoNormalizedString()Retrieves a normalized string representation of this value.abstract java.lang.StringtoNormalizedString(boolean ignoreFieldNameCase, boolean ignoreValueCase, boolean ignoreArrayOrder)Retrieves a normalized string representation of this value using the provided settings.abstract voidtoNormalizedString(java.lang.StringBuilder buffer)Appends a normalized string representation of this value to the provided buffer.abstract voidtoNormalizedString(java.lang.StringBuilder buffer, boolean ignoreFieldNameCase, boolean ignoreValueCase, boolean ignoreArrayOrder)Appends a normalized string representation of this value to the provided buffer using the provided settings.abstract JSONValuetoNormalizedValue(boolean ignoreFieldNameCase, boolean ignoreValueCase, boolean ignoreArrayOrder)Retrieves a normalized representation of this value using the provided settings.abstract java.lang.StringtoSingleLineString()Retrieves a single-line string representation of this value as it should appear in a JSON object, including any necessary quoting, escaping, etc.abstract voidtoSingleLineString(java.lang.StringBuilder buffer)Appends a single-line string representation of this value (as it should appear in a JSON object, including any necessary quoting, escaping, etc.) to the provided buffer.abstract java.lang.StringtoString()Retrieves a string representation of this value as it should appear in a JSON object, including any necessary quoting, escaping, etc.abstract voidtoString(java.lang.StringBuilder buffer)Appends a string representation of this value (as it should appear in a JSON object, including any necessary quoting, escaping, etc.) to the provided buffer.
-
-
-
Constructor Detail
-
JSONValue
public JSONValue()
-
-
Method Detail
-
hashCode
public abstract int hashCode()
Retrieves a hash code for this JSON value.- Overrides:
hashCodein classjava.lang.Object- Returns:
- The hash code for this JSON value.
-
equals
public abstract boolean equals(@Nullable java.lang.Object o)
Indicates whether the provided object is equal to this JSON value.- Overrides:
equalsin classjava.lang.Object- Parameters:
o- The object to compare against this JSON value.- Returns:
trueif the provided object is considered equal to this JSON value, orfalseif not.
-
equals
public abstract boolean equals(@NotNull 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. Note that not all constraints will apply to all data types.- Parameters:
v- The JSON value for which to make the determination. It must not benull.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.- Returns:
trueif this JSON value is considered equal to the provided JSON value (subject to the specified constraints), orfalseif not.
-
toString
@NotNull public abstract java.lang.String toString()
Retrieves a string representation of this value as it should appear in a JSON object, including any necessary quoting, escaping, etc. If the object containing this value was decoded from a string, then this method will use the same string representation as in that original object. Otherwise, the string representation will be constructed.- Overrides:
toStringin classjava.lang.Object- Returns:
- A string representation of this value as it should appear in a JSON object.
-
toString
public abstract void toString(@NotNull java.lang.StringBuilder buffer)
Appends a string representation of this value (as it should appear in a JSON object, including any necessary quoting, escaping, etc.) to the provided buffer. If the object containing this value was decoded from a string, then this method will use the same string representation as in that original object. Otherwise, the string representation will be constructed.- Parameters:
buffer- The buffer to which the information should be appended.
-
toSingleLineString
@NotNull public abstract java.lang.String toSingleLineString()
Retrieves a single-line string representation of this value as it should appear in a JSON object, including any necessary quoting, escaping, etc.- Returns:
- A string representation of this value as it should appear in a JSON object.
-
toSingleLineString
public abstract void toSingleLineString(@NotNull java.lang.StringBuilder buffer)
Appends a single-line string representation of this value (as it should appear in a JSON object, including any necessary quoting, escaping, etc.) to the provided buffer.- Parameters:
buffer- The buffer to which the information should be appended.
-
toNormalizedString
@NotNull public abstract java.lang.String toNormalizedString()
Retrieves a normalized string representation of this value. All equivalent JSON values must have equivalent normalized representations, even if there are other legal representations for the value.- Returns:
- A normalized string representation of this value.
-
toNormalizedString
public abstract void toNormalizedString(@NotNull java.lang.StringBuilder buffer)
Appends a normalized string representation of this value to the provided buffer. All equivalent JSON values must have equivalent normalized representations, even if there are other legal representations for the value.- Parameters:
buffer- The buffer to which the information should be appended.
-
toNormalizedString
@NotNull public abstract java.lang.String toNormalizedString(boolean ignoreFieldNameCase, boolean ignoreValueCase, boolean ignoreArrayOrder)
Retrieves a normalized string representation of this value using the provided settings.- Parameters:
ignoreFieldNameCase- Indicates whether field names should be treated in a case-sensitive (iffalse) or case-insensitive (iftrue) manner.ignoreValueCase- Indicates whether string field values should be treated in a case-sensitive (iffalse) or case-insensitive (iftrue) manner.ignoreArrayOrder- Indicates whether the order of elements in an array should be considered significant (iffalse) or insignificant (iftrue).- Returns:
- A normalized string representation of this value.
-
toNormalizedString
public abstract void toNormalizedString(@NotNull java.lang.StringBuilder buffer, boolean ignoreFieldNameCase, boolean ignoreValueCase, boolean ignoreArrayOrder)
Appends a normalized string representation of this value to the provided buffer using the provided settings.- Parameters:
buffer- The buffer to which the information should be appended.ignoreFieldNameCase- Indicates whether field names should be treated in a case-sensitive (iffalse) or case-insensitive (iftrue) manner.ignoreValueCase- Indicates whether string field values should be treated in a case-sensitive (iffalse) or case-insensitive (iftrue) manner.ignoreArrayOrder- Indicates whether the order of elements in an array should be considered significant (iffalse) or insignificant (iftrue).
-
toNormalizedValue
@NotNull public abstract JSONValue toNormalizedValue(boolean ignoreFieldNameCase, boolean ignoreValueCase, boolean ignoreArrayOrder)
Retrieves a normalized representation of this value using the provided settings.- Parameters:
ignoreFieldNameCase- Indicates whether field names should be treated in a case-sensitive (iffalse) or case-insensitive (iftrue) manner.ignoreValueCase- Indicates whether string field values should be treated in a case-sensitive (iffalse) or case-insensitive (iftrue) manner.ignoreArrayOrder- Indicates whether the order of elements in an array should be considered significant (iffalse) or insignificant (iftrue).- Returns:
- A normalized representation of this value using the provided settings.
-
appendToJSONBuffer
public abstract void appendToJSONBuffer(@NotNull JSONBuffer buffer)
Appends this value to the provided JSON buffer. This will not include a field name, so it should only be used for Boolean value elements in an array.- Parameters:
buffer- The JSON buffer to which this value should be appended.
-
appendToJSONBuffer
public abstract void appendToJSONBuffer(@NotNull java.lang.String fieldName, @NotNull JSONBuffer buffer)
Appends a field with the given name and this value to the provided JSON buffer.- Parameters:
fieldName- The name to use for the field.buffer- The JSON buffer to which this value should be appended.
-
compareTo
public final int compareTo(@NotNull JSONValue value)
Compares the provided value to this value to determine their relative order in a sorted list. The comparison will be based purely on a lexicographic comparison of the normalized representations of the values.- Specified by:
compareToin interfacejava.lang.Comparable<JSONValue>- Parameters:
value- The value to compare to this value. It must not benull.- Returns:
- A negative integer if this value should come before the provided value in a sorted list, a positive integer if this value should come after the provided value in a sorted list, or zero if the provided value can be considered equal to this value.
-
-