public abstract class JsonElement
extends java.lang.Object
Abstract base class for JSON elements (boolean, number, string, array, object). JSON also permits null values; where appropriate a nullable JsonElement (type JsonElement?) should be used.
JsonBoolean
, JsonNumber
, JsonString
, JsonArray
, JsonObject
, JsonElementStream
.
Modifier and Type | Field and Description |
---|---|
static int |
TYPE_ARRAY
Type code for JSON array values.
|
static int |
TYPE_BOOLEAN
Type code for JSON boolean values.
|
static int |
TYPE_NUMBER
Type code for JSON number values.
|
static int |
TYPE_OBJECT
Type code for JSON object values.
|
static int |
TYPE_STRING
Type code for JSON string values.
|
Constructor and Description |
---|
JsonElement() |
Modifier and Type | Method and Description |
---|---|
static JsonElement |
applyVersion(int version,
JsonElement toElement)
|
static java.lang.String |
format(JsonElement element)
Return JSON element (including
null ) converted to a string. |
abstract int |
getType()
Return type of JSON element.
|
static JsonElement |
parse(java.lang.String text)
Return (nullable) String converted to parsed JSON element (including
null ). |
static JsonArray |
parseArray(java.lang.String text)
Return string converted to parsed JSON array.
|
static JsonObject |
parseObject(java.lang.String text)
Return string converted to parsed JSON object.
|
static JsonElement |
parseOptimized(java.lang.String text,
boolean optimized)
Return (nullable) String converted to parsed JSON element (including
null ). |
abstract java.lang.String |
toString() |
public static final int TYPE_BOOLEAN
Type code for JSON boolean values.
public static final int TYPE_NUMBER
Type code for JSON number values.
public static final int TYPE_STRING
Type code for JSON string values.
public static final int TYPE_ARRAY
Type code for JSON array values.
public static final int TYPE_OBJECT
Type code for JSON object values.
public static JsonElement applyVersion(int version, JsonElement toElement)
Apply version
(recursively) to all JsonObject
instances within toElement
.
version
- Data version.toElement
- (nullable) Element to which version should be applied.public static java.lang.String format(JsonElement element)
Return JSON element (including null
) converted to a string.
element
- (nullable) JSON element.null
) converted to a string.public abstract int getType()
Return type of JSON element.
constants.
public static JsonElement parse(java.lang.String text)
Return (nullable) String converted to parsed JSON element (including null
).
text
- Text to be parsed. Must be in JSON element format (null, boolean, number, string, array or object).null
).public static JsonArray parseArray(java.lang.String text)
Return string converted to parsed JSON array.
text
- Text to be parsed. Must be in JSON array format.public static JsonObject parseObject(java.lang.String text)
Return string converted to parsed JSON object.
text
- Text to be parsed. Must be in JSON object format.public static JsonElement parseOptimized(java.lang.String text, boolean optimized)
Return (nullable) String converted to parsed JSON element (including null
).
If optimized
is true
, any returned JSON objects will use JsonObject.optimizedEntries
to
contain key/value pairs for all JSON fields whose name does not contain "@", rather than regular map entries.
text
- Text to be parsed. Must be in JSON element format (null, boolean, number, string, array or object).optimized
- Should "property" (non-annotation) entries of JSON objects be held in JsonObject.optimizedEntries
.null
).public abstract java.lang.String toString()
toString
in class java.lang.Object