JsonArray
, JsonNull
, JsonObject
, JsonPrimitive
public abstract class JsonElement
extends java.lang.Object
JsonObject
, a
JsonArray
, a JsonPrimitive
or a JsonNull
.Constructor | Description |
---|---|
JsonElement() |
Modifier and Type | Method | Description |
---|---|---|
abstract JsonElement |
deepCopy() |
Returns a deep copy of this element.
|
java.math.BigDecimal |
getAsBigDecimal() |
convenience method to get this element as a
BigDecimal . |
java.math.BigInteger |
getAsBigInteger() |
convenience method to get this element as a
BigInteger . |
boolean |
getAsBoolean() |
convenience method to get this element as a boolean value.
|
byte |
getAsByte() |
convenience method to get this element as a primitive byte value.
|
char |
getAsCharacter() |
convenience method to get this element as a primitive character value.
|
double |
getAsDouble() |
convenience method to get this element as a primitive double value.
|
float |
getAsFloat() |
convenience method to get this element as a primitive float value.
|
int |
getAsInt() |
convenience method to get this element as a primitive integer value.
|
JsonArray |
getAsJsonArray() |
convenience method to get this element as a
JsonArray . |
JsonNull |
getAsJsonNull() |
convenience method to get this element as a
JsonNull . |
JsonObject |
getAsJsonObject() |
convenience method to get this element as a
JsonObject . |
JsonPrimitive |
getAsJsonPrimitive() |
convenience method to get this element as a
JsonPrimitive . |
long |
getAsLong() |
convenience method to get this element as a primitive long value.
|
java.lang.Number |
getAsNumber() |
convenience method to get this element as a
Number . |
short |
getAsShort() |
convenience method to get this element as a primitive short value.
|
java.lang.String |
getAsString() |
convenience method to get this element as a string value.
|
boolean |
isJsonArray() |
provides check for verifying if this element is an array or not.
|
boolean |
isJsonNull() |
provides check for verifying if this element represents a null value or not.
|
boolean |
isJsonObject() |
provides check for verifying if this element is a Json object or not.
|
boolean |
isJsonPrimitive() |
provides check for verifying if this element is a primitive or not.
|
java.lang.String |
toString() |
Returns a String representation of this element.
|
public abstract JsonElement deepCopy()
public boolean isJsonArray()
JsonArray
, false otherwise.public boolean isJsonObject()
JsonObject
, false otherwise.public boolean isJsonPrimitive()
JsonPrimitive
, false otherwise.public boolean isJsonNull()
JsonNull
, false otherwise.public JsonObject getAsJsonObject()
JsonObject
. If the element is of some
other type, a IllegalStateException
will result. Hence it is best to use this method
after ensuring that this element is of the desired type by calling isJsonObject()
first.JsonObject
.java.lang.IllegalStateException
- if the element is of another type.public JsonArray getAsJsonArray()
JsonArray
. If the element is of some
other type, a IllegalStateException
will result. Hence it is best to use this method
after ensuring that this element is of the desired type by calling isJsonArray()
first.JsonArray
.java.lang.IllegalStateException
- if the element is of another type.public JsonPrimitive getAsJsonPrimitive()
JsonPrimitive
. If the element is of some
other type, a IllegalStateException
will result. Hence it is best to use this method
after ensuring that this element is of the desired type by calling isJsonPrimitive()
first.JsonPrimitive
.java.lang.IllegalStateException
- if the element is of another type.public JsonNull getAsJsonNull()
JsonNull
. If the element is of some
other type, a IllegalStateException
will result. Hence it is best to use this method
after ensuring that this element is of the desired type by calling isJsonNull()
first.JsonNull
.java.lang.IllegalStateException
- if the element is of another type.public boolean getAsBoolean()
java.lang.ClassCastException
- if the element is of not a JsonPrimitive
and is not a valid
boolean value.java.lang.IllegalStateException
- if the element is of the type JsonArray
but contains
more than a single element.public java.lang.Number getAsNumber()
Number
.Number
.java.lang.ClassCastException
- if the element is of not a JsonPrimitive
and is not a valid
number.java.lang.IllegalStateException
- if the element is of the type JsonArray
but contains
more than a single element.public java.lang.String getAsString()
java.lang.ClassCastException
- if the element is of not a JsonPrimitive
and is not a valid
string value.java.lang.IllegalStateException
- if the element is of the type JsonArray
but contains
more than a single element.public double getAsDouble()
java.lang.ClassCastException
- if the element is of not a JsonPrimitive
and is not a valid
double value.java.lang.IllegalStateException
- if the element is of the type JsonArray
but contains
more than a single element.public float getAsFloat()
java.lang.ClassCastException
- if the element is of not a JsonPrimitive
and is not a valid
float value.java.lang.IllegalStateException
- if the element is of the type JsonArray
but contains
more than a single element.public long getAsLong()
java.lang.ClassCastException
- if the element is of not a JsonPrimitive
and is not a valid
long value.java.lang.IllegalStateException
- if the element is of the type JsonArray
but contains
more than a single element.public int getAsInt()
java.lang.ClassCastException
- if the element is of not a JsonPrimitive
and is not a valid
integer value.java.lang.IllegalStateException
- if the element is of the type JsonArray
but contains
more than a single element.public byte getAsByte()
java.lang.ClassCastException
- if the element is of not a JsonPrimitive
and is not a valid
byte value.java.lang.IllegalStateException
- if the element is of the type JsonArray
but contains
more than a single element.public char getAsCharacter()
java.lang.ClassCastException
- if the element is of not a JsonPrimitive
and is not a valid
char value.java.lang.IllegalStateException
- if the element is of the type JsonArray
but contains
more than a single element.public java.math.BigDecimal getAsBigDecimal()
BigDecimal
.BigDecimal
.java.lang.ClassCastException
- if the element is of not a JsonPrimitive
.
* @throws NumberFormatException if the element is not a valid BigDecimal
.java.lang.IllegalStateException
- if the element is of the type JsonArray
but contains
more than a single element.public java.math.BigInteger getAsBigInteger()
BigInteger
.BigInteger
.java.lang.ClassCastException
- if the element is of not a JsonPrimitive
.java.lang.NumberFormatException
- if the element is not a valid BigInteger
.java.lang.IllegalStateException
- if the element is of the type JsonArray
but contains
more than a single element.public short getAsShort()
java.lang.ClassCastException
- if the element is of not a JsonPrimitive
and is not a valid
short value.java.lang.IllegalStateException
- if the element is of the type JsonArray
but contains
more than a single element.public java.lang.String toString()
toString
in class java.lang.Object
Copyright © 2018. All rights reserved.