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.-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionCreates a JsonElement with typeJsonElementType.NULL.JsonElement(@Nullable Boolean value) Creates a JsonElement with typeJsonElementType.BOOLEANif value is non-null orJsonElementType.NULLif null.JsonElement(@Nullable Double value) Creates a JsonElement with typeJsonElementType.DOUBLEif value is non-null orJsonElementType.NULLif null.JsonElement(@Nullable Float value) Creates a JsonElement with typeJsonElementType.DOUBLEif value is non-null orJsonElementType.NULLif null.JsonElement(@Nullable Integer value) Creates a JsonElement with typeJsonElementType.LONGif value is non-null orJsonElementType.NULLif null.JsonElement(@Nullable Long value) Creates a JsonElement with typeJsonElementType.LONGif value is non-null orJsonElementType.NULLif null.JsonElement(@Nullable String value) Creates a JsonElement with typeJsonElementType.STRINGif value is non-null orJsonElementType.NULLif null.JsonElement(@Nullable JsonArray value) Creates a JsonElement with typeJsonElementType.JSON_ARRAYif value is non-null orJsonElementType.NULLif null.JsonElement(@Nullable JsonObject value) Creates a JsonElement with typeJsonElementType.JSON_OBJECTif value is non-null orJsonElementType.NULLif null. -
Method Summary
Modifier and TypeMethodDescriptionasArray()Returns this JsonElement's value as aJsonArrayif its type isJsonElementType.JSON_ARRAYor else throwsJsonElementTypeException.booleanReturns this JsonElement's value as a boolean if its type isJsonElementType.BOOLEANor else throwsJsonElementTypeException.doubleasDouble()Returns this JsonElement's value as a double if its type isJsonElementType.DOUBLEor else throwsJsonElementTypeException.floatasFloat()Returns this JsonElement's value as a float if its type isJsonElementType.DOUBLEor else throwsJsonElementTypeException.intasInt()Returns this JsonElement's value as an int if its type isJsonElementType.LONGor else throwsJsonElementTypeException.longasLong()Returns this JsonElement's value as a long if its type isJsonElementType.LONGor else throwsJsonElementTypeException.asObject()Returns this JsonElement's value as aJsonObjectif its type isJsonElementType.JSON_OBJECTor else throwsJsonElementTypeException.asString()Returns this JsonElement's value as a String if its type isJsonElementType.STRINGor else throwsJsonElementTypeException.getType()booleanisNull()toString()Formats thisJsonElementas a string with no indentation.toString(int spaces) Formats thisJsonElementas a string with specified spaces for indentation.
-
Field Details
-
NULL
Represents the JSON null value.
-
-
Constructor Details
-
JsonElement
public JsonElement()Creates a JsonElement with typeJsonElementType.NULL. -
JsonElement
Creates a JsonElement with typeJsonElementType.LONGif value is non-null orJsonElementType.NULLif null.- Parameters:
value- the value of the JsonElement
-
JsonElement
Creates a JsonElement with typeJsonElementType.LONGif value is non-null orJsonElementType.NULLif null.- Parameters:
value- the value of the JsonElement
-
JsonElement
Creates a JsonElement with typeJsonElementType.DOUBLEif value is non-null orJsonElementType.NULLif null.- Parameters:
value- the value of the JsonElement
-
JsonElement
Creates a JsonElement with typeJsonElementType.DOUBLEif value is non-null orJsonElementType.NULLif null.- Parameters:
value- the value of the JsonElement
-
JsonElement
Creates a JsonElement with typeJsonElementType.STRINGif value is non-null orJsonElementType.NULLif null.- Parameters:
value- the value of the JsonElement
-
JsonElement
Creates a JsonElement with typeJsonElementType.JSON_OBJECTif value is non-null orJsonElementType.NULLif null.- Parameters:
value- the value of the JsonElement
-
JsonElement
Creates a JsonElement with typeJsonElementType.JSON_ARRAYif value is non-null orJsonElementType.NULLif null.- Parameters:
value- the value of the JsonElement
-
JsonElement
Creates a JsonElement with typeJsonElementType.BOOLEANif value is non-null orJsonElementType.NULLif 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.BOOLEANor else throwsJsonElementTypeException.- Returns:
- value as boolean
-
asInt
public int asInt()Returns this JsonElement's value as an int if its type isJsonElementType.LONGor else throwsJsonElementTypeException.- Returns:
- value as int
-
asLong
public long asLong()Returns this JsonElement's value as a long if its type isJsonElementType.LONGor else throwsJsonElementTypeException.- Returns:
- value as long
-
asFloat
public float asFloat()Returns this JsonElement's value as a float if its type isJsonElementType.DOUBLEor else throwsJsonElementTypeException.- Returns:
- value as float
-
asDouble
public double asDouble()Returns this JsonElement's value as a double if its type isJsonElementType.DOUBLEor else throwsJsonElementTypeException.- Returns:
- value as double
-
asString
Returns this JsonElement's value as a String if its type isJsonElementType.STRINGor else throwsJsonElementTypeException.- Returns:
- value as String
-
asObject
Returns this JsonElement's value as aJsonObjectif its type isJsonElementType.JSON_OBJECTor else throwsJsonElementTypeException.- Returns:
- value as
JsonObject
-
asArray
Returns this JsonElement's value as aJsonArrayif its type isJsonElementType.JSON_ARRAYor 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 thisJsonElementas a string with no indentation. -
toString
Formats thisJsonElementas a string with specified spaces for indentation.- Parameters:
spaces- the spaces for each indentation- Returns:
- formatted JSON string with spaces for indentation
-