|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.google.gson.JsonElement
public abstract class JsonElement
A class representing an element of Json. It could either be a JsonObject
, a
JsonArray
or a JsonPrimitive
.
Constructor Summary | |
---|---|
JsonElement()
This is an abstract class and can not be instantiated directly. |
Method Summary | |
---|---|
boolean |
getAsBoolean()
convenience method to get this element as a boolean 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 . |
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. |
Number |
getAsNumber()
convenience method to get this element as a Number . |
short |
getAsShort()
convenience method to get this element as a primitive short value. |
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 |
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. |
String |
toString()
Returns a String representation of this element. |
protected abstract void |
toString(StringBuilder sb)
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public JsonElement()
JsonObject
, JsonPrimitive
, or
JsonArray
.
Method Detail |
---|
public boolean isJsonArray()
JsonArray
, false otherwise.public boolean isJsonObject()
JsonObject
, false otherwise.public boolean isJsonPrimitive()
JsonPrimitive
, false otherwise.public JsonObject getAsJsonObject()
JsonObject
. If the element is of some
other type, a ClassCastException
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
.
ClassCastException
- if the element is of another type.public JsonArray getAsJsonArray()
JsonArray
. If the element is of some
other type, a ClassCastException
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
.
ClassCastException
- if the element is of another type.public JsonPrimitive getAsJsonPrimitive()
JsonPrimitive
. If the element is of some
other type, a ClassCastException
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
.
ClassCastException
- if the element is of another type.public boolean getAsBoolean()
ClassCastException
- if the element is of not a JsonPrimitive
and is not a valid
boolean value.
IllegalStateException
- if the element is of the type JsonArray
but contains
more than a single element.public Number getAsNumber()
Number
.
Number
.
ClassCastException
- if the element is of not a JsonPrimitive
and is not a valid
number.
IllegalStateException
- if the element is of the type JsonArray
but contains
more than a single element.public String getAsString()
ClassCastException
- if the element is of not a JsonPrimitive
and is not a valid
string value.
IllegalStateException
- if the element is of the type JsonArray
but contains
more than a single element.public double getAsDouble()
ClassCastException
- if the element is of not a JsonPrimitive
and is not a valid
double value.
IllegalStateException
- if the element is of the type JsonArray
but contains
more than a single element.public float getAsFloat()
ClassCastException
- if the element is of not a JsonPrimitive
and is not a valid
float value.
IllegalStateException
- if the element is of the type JsonArray
but contains
more than a single element.public long getAsLong()
ClassCastException
- if the element is of not a JsonPrimitive
and is not a valid
long value.
IllegalStateException
- if the element is of the type JsonArray
but contains
more than a single element.public int getAsInt()
ClassCastException
- if the element is of not a JsonPrimitive
and is not a valid
integer value.
IllegalStateException
- if the element is of the type JsonArray
but contains
more than a single element.public short getAsShort()
ClassCastException
- if the element is of not a JsonPrimitive
and is not a valid
short value.
IllegalStateException
- if the element is of the type JsonArray
but contains
more than a single element.public String toString()
toString
in class Object
protected abstract void toString(StringBuilder sb)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |