JsonElement (Gson 2.3.1 API)
Date: 2014-11-20

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## com.google.gson
Class JsonElement

    java.lang.Object
      com.google.gson.JsonElement

Direct Known Subclasses:
  JsonArray, JsonNull, JsonObject, JsonPrimitive

    public abstract class JsonElement

extends Object

A class representing an element of Json. It could either be a `JsonObject`, a `JsonArray`, a `JsonPrimitive` or a `JsonNull`.

Author:
  Inderjeet Singh, Joel Leitch

Constructor Summary
`JsonElement()`

Method Summary
`BigDecimal` | `getAsBigDecimal()` convenience method to get this element as a `BigDecimal`.
`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.
`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` | `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.
`String` | `toString()` Returns a String representation of this element.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

Constructor Detail

### JsonElement

    public JsonElement()

Method Detail

### isJsonArray

    public boolean isJsonArray()

  provides check for verifying if this element is an array or not.

  Returns:
    true if this element is of type `JsonArray`, false otherwise.

### isJsonObject

    public boolean isJsonObject()

  provides check for verifying if this element is a Json object or not.

  Returns:
    true if this element is of type `JsonObject`, false otherwise.

### isJsonPrimitive

    public boolean isJsonPrimitive()

  provides check for verifying if this element is a primitive or not.

  Returns:
    true if this element is of type `JsonPrimitive`, false otherwise.

### isJsonNull

    public boolean isJsonNull()

  provides check for verifying if this element represents a null value or not.

  Returns:
    true if this element is of type `JsonNull`, false otherwise.
  Since:
    1.2

### getAsJsonObject

    public JsonObject getAsJsonObject()

  convenience method to get this element as a `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.

  Returns:
    get this element as a `JsonObject`.
  Throws:
    `IllegalStateException` - if the element is of another type.

### getAsJsonArray

    public JsonArray getAsJsonArray()

  convenience method to get this element as a `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.

  Returns:
    get this element as a `JsonArray`.
  Throws:
    `IllegalStateException` - if the element is of another type.

### getAsJsonPrimitive

    public JsonPrimitive getAsJsonPrimitive()

  convenience method to get this element as a `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.

  Returns:
    get this element as a `JsonPrimitive`.
  Throws:
    `IllegalStateException` - if the element is of another type.

### getAsJsonNull

    public JsonNull getAsJsonNull()

  convenience method to get this element as a `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.

  Returns:
    get this element as a `JsonNull`.
  Throws:
    `IllegalStateException` - if the element is of another type.
  Since:
    1.2

### getAsBoolean

    public boolean getAsBoolean()

  convenience method to get this element as a boolean value.

  Returns:
    get this element as a primitive boolean value.
  Throws:
    `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.

### getAsNumber

    public Number getAsNumber()

  convenience method to get this element as a `Number`.

  Returns:
    get this element as a `Number`.
  Throws:
    `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.

### getAsString

    public String getAsString()

  convenience method to get this element as a string value.

  Returns:
    get this element as a string value.
  Throws:
    `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.

### getAsDouble

    public double getAsDouble()

  convenience method to get this element as a primitive double value.

  Returns:
    get this element as a primitive double value.
  Throws:
    `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.

### getAsFloat

    public float getAsFloat()

  convenience method to get this element as a primitive float value.

  Returns:
    get this element as a primitive float value.
  Throws:
    `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.

### getAsLong

    public long getAsLong()

  convenience method to get this element as a primitive long value.

  Returns:
    get this element as a primitive long value.
  Throws:
    `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.

### getAsInt

    public int getAsInt()

  convenience method to get this element as a primitive integer value.

  Returns:
    get this element as a primitive integer value.
  Throws:
    `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.

### getAsByte

    public byte getAsByte()

  convenience method to get this element as a primitive byte value.

  Returns:
    get this element as a primitive byte value.
  Throws:
    `ClassCastException` - if the element is of not a `JsonPrimitive` and is not a valid byte value.
    `IllegalStateException` - if the element is of the type `JsonArray` but contains more than a single element.
  Since:
    1.3

### getAsCharacter

    public char getAsCharacter()

  convenience method to get this element as a primitive character value.

  Returns:
    get this element as a primitive char value.
  Throws:
    `ClassCastException` - if the element is of not a `JsonPrimitive` and is not a valid char value.
    `IllegalStateException` - if the element is of the type `JsonArray` but contains more than a single element.
  Since:
    1.3

### getAsBigDecimal

    public BigDecimal getAsBigDecimal()

  convenience method to get this element as a `BigDecimal`.

  Returns:
    get this element as a `BigDecimal`.
  Throws:
    `ClassCastException` - if the element is of not a `JsonPrimitive`. * @throws NumberFormatException if the element is not a valid `BigDecimal`.
    `IllegalStateException` - if the element is of the type `JsonArray` but contains more than a single element.
  Since:
    1.2

### getAsBigInteger

    public BigInteger getAsBigInteger()

  convenience method to get this element as a `BigInteger`.

  Returns:
    get this element as a `BigInteger`.
  Throws:
    `ClassCastException` - if the element is of not a `JsonPrimitive`.
    `NumberFormatException` - if the element is not a valid `BigInteger`.
    `IllegalStateException` - if the element is of the type `JsonArray` but contains more than a single element.
  Since:
    1.2

### getAsShort

    public short getAsShort()

  convenience method to get this element as a primitive short value.

  Returns:
    get this element as a primitive short value.
  Throws:
    `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.

### toString

    public String toString()

  Returns a String representation of this element.

  Overrides:
    `toString` in class `Object`

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2008–2014 Google, Inc.. All rights reserved.