java.lang.Object
technology.sola.json.JsonElement
JsonElement represents any valid JSON value. Valid JSON values include
JsonObject
, JsonArray
, string,
number, true, false and null.-
Constructor Summary
ConstructorsConstructorDescriptionCreates a JsonElement with typeJsonElementType.NULL
.JsonElement
(@Nullable Boolean value) Creates a JsonElement with typeJsonElementType.BOOLEAN
if value is non-null orJsonElementType.NULL
if null.JsonElement
(@Nullable Double value) Creates a JsonElement with typeJsonElementType.DOUBLE
if value is non-null orJsonElementType.NULL
if null.JsonElement
(@Nullable Float value) Creates a JsonElement with typeJsonElementType.DOUBLE
if value is non-null orJsonElementType.NULL
if null.JsonElement
(@Nullable Integer value) Creates a JsonElement with typeJsonElementType.LONG
if value is non-null orJsonElementType.NULL
if null.JsonElement
(@Nullable Long value) Creates a JsonElement with typeJsonElementType.LONG
if value is non-null orJsonElementType.NULL
if null.JsonElement
(@Nullable String value) Creates a JsonElement with typeJsonElementType.STRING
if value is non-null orJsonElementType.NULL
if null.JsonElement
(@Nullable JsonArray value) Creates a JsonElement with typeJsonElementType.JSON_ARRAY
if value is non-null orJsonElementType.NULL
if null.JsonElement
(@Nullable JsonObject value) Creates a JsonElement with typeJsonElementType.JSON_OBJECT
if value is non-null orJsonElementType.NULL
if null. -
Method Summary
Modifier and TypeMethodDescriptionasArray()
Returns this JsonElement's value as aJsonArray
if its type isJsonElementType.JSON_ARRAY
or else throwsJsonElementTypeException
.boolean
Returns this JsonElement's value as a boolean if its type isJsonElementType.BOOLEAN
or else throwsJsonElementTypeException
.double
asDouble()
Returns this JsonElement's value as a double if its type isJsonElementType.DOUBLE
or else throwsJsonElementTypeException
.float
asFloat()
Returns this JsonElement's value as a float if its type isJsonElementType.DOUBLE
or else throwsJsonElementTypeException
.int
asInt()
Returns this JsonElement's value as an int if its type isJsonElementType.LONG
or else throwsJsonElementTypeException
.long
asLong()
Returns this JsonElement's value as a long if its type isJsonElementType.LONG
or else throwsJsonElementTypeException
.asObject()
Returns this JsonElement's value as aJsonObject
if its type isJsonElementType.JSON_OBJECT
or else throwsJsonElementTypeException
.asString()
Returns this JsonElement's value as a String if its type isJsonElementType.STRING
or else throwsJsonElementTypeException
.getType()
boolean
isNull()
toString()
Formats thisJsonElement
as a string with no indentation.toString
(int spaces) Formats thisJsonElement
as a string with specified spaces for indentation.
-
Constructor Details
-
JsonElement
public JsonElement()Creates a JsonElement with typeJsonElementType.NULL
. -
JsonElement
Creates a JsonElement with typeJsonElementType.LONG
if value is non-null orJsonElementType.NULL
if null.- Parameters:
value
- the value of the JsonElement
-
JsonElement
Creates a JsonElement with typeJsonElementType.LONG
if value is non-null orJsonElementType.NULL
if null.- Parameters:
value
- the value of the JsonElement
-
JsonElement
Creates a JsonElement with typeJsonElementType.DOUBLE
if value is non-null orJsonElementType.NULL
if null.- Parameters:
value
- the value of the JsonElement
-
JsonElement
Creates a JsonElement with typeJsonElementType.DOUBLE
if value is non-null orJsonElementType.NULL
if null.- Parameters:
value
- the value of the JsonElement
-
JsonElement
Creates a JsonElement with typeJsonElementType.STRING
if value is non-null orJsonElementType.NULL
if null.- Parameters:
value
- the value of the JsonElement
-
JsonElement
Creates a JsonElement with typeJsonElementType.JSON_OBJECT
if value is non-null orJsonElementType.NULL
if null.- Parameters:
value
- the value of the JsonElement
-
JsonElement
Creates a JsonElement with typeJsonElementType.JSON_ARRAY
if value is non-null orJsonElementType.NULL
if null.- Parameters:
value
- the value of the JsonElement
-
JsonElement
Creates a JsonElement with typeJsonElementType.BOOLEAN
if value is non-null orJsonElementType.NULL
if null.- Parameters:
value
- the value of the JsonElement
-
-
Method Details
-
asBoolean
public boolean asBoolean()Returns this JsonElement's value as a boolean if its type isJsonElementType.BOOLEAN
or else throwsJsonElementTypeException
.- Returns:
- value as boolean
-
asInt
public int asInt()Returns this JsonElement's value as an int if its type isJsonElementType.LONG
or else throwsJsonElementTypeException
.- Returns:
- value as int
-
asLong
public long asLong()Returns this JsonElement's value as a long if its type isJsonElementType.LONG
or else throwsJsonElementTypeException
.- Returns:
- value as long
-
asFloat
public float asFloat()Returns this JsonElement's value as a float if its type isJsonElementType.DOUBLE
or else throwsJsonElementTypeException
.- Returns:
- value as float
-
asDouble
public double asDouble()Returns this JsonElement's value as a double if its type isJsonElementType.DOUBLE
or else throwsJsonElementTypeException
.- Returns:
- value as double
-
asString
Returns this JsonElement's value as a String if its type isJsonElementType.STRING
or else throwsJsonElementTypeException
.- Returns:
- value as String
-
asObject
Returns this JsonElement's value as aJsonObject
if its type isJsonElementType.JSON_OBJECT
or else throwsJsonElementTypeException
.- Returns:
- value as
JsonObject
-
asArray
Returns this JsonElement's value as aJsonArray
if its type isJsonElementType.JSON_ARRAY
or else throwsJsonElementTypeException
.- Returns:
- value as
JsonArray
-
isNull
public boolean isNull()- Returns:
- true if this JsonElement's type is
JsonElementType.NULL
-
getType
- Returns:
- the type of this JsonElement
-
toString
Formats thisJsonElement
as a string with no indentation. -
toString
Formats thisJsonElement
as a string with specified spaces for indentation.- Parameters:
spaces
- the spaces for each indentation- Returns:
- formatted JSON string with spaces for indentation
-