public final class

JsonPrimitive

extends JsonElement
java.lang.Object
   ↳ com.google.gson.JsonElement
     ↳ com.google.gson.JsonPrimitive

Class Overview

A class representing a Json primitive value. A primitive value is either a String, a Java primitive, or a Java primitive wrapper type.

Summary

Public Constructors
JsonPrimitive(Boolean bool)
Create a primitive containing a boolean value.
JsonPrimitive(Number number)
Create a primitive containing a Number.
JsonPrimitive(String string)
Create a primitive containing a String value.
JsonPrimitive(Character c)
Create a primitive containing a character.
Public Methods
boolean equals(Object obj)
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.
float getAsFloat()
convenience method to get this element as a float.
int getAsInt()
convenience method to get this element as a primitive integer.
long getAsLong()
convenience method to get this element as a primitive long.
Number getAsNumber()
convenience method to get this element as a Number.
short getAsShort()
convenience method to get this element as a primitive short.
String getAsString()
convenience method to get this element as a String.
int hashCode()
boolean isBoolean()
Check whether this primitive contains a boolean value.
boolean isNumber()
Check whether this primitive contains a Number.
boolean isString()
Check whether this primitive contains a String value.
[Expand]
Inherited Methods
From class com.google.gson.JsonElement
From class java.lang.Object

Public Constructors

public JsonPrimitive (Boolean bool)

Create a primitive containing a boolean value.

Parameters
bool the value to create the primitive with.

public JsonPrimitive (Number number)

Create a primitive containing a Number.

Parameters
number the value to create the primitive with.

public JsonPrimitive (String string)

Create a primitive containing a String value.

Parameters
string the value to create the primitive with.

public JsonPrimitive (Character c)

Create a primitive containing a character. The character is turned into a one character String since Json only supports String.

Parameters
c the value to create the primitive with.

Public Methods

public boolean equals (Object obj)

public BigDecimal getAsBigDecimal ()

convenience method to get this element as a BigDecimal.

Returns
Throws
NumberFormatException if the value contained is not a valid BigDecimal.

public BigInteger getAsBigInteger ()

convenience method to get this element as a BigInteger.

Returns
Throws
NumberFormatException if the value contained is not a valid BigInteger.

public boolean getAsBoolean ()

convenience method to get this element as a boolean value.

Returns
  • get this element as a primitive boolean value.

public byte getAsByte ()

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

Returns
  • get this element as a primitive byte value.

public char getAsCharacter ()

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

Returns
  • get this element as a primitive char value.

public double getAsDouble ()

convenience method to get this element as a primitive double.

Returns
  • get this element as a primitive double.
Throws
NumberFormatException if the value contained is not a valid double.

public float getAsFloat ()

convenience method to get this element as a float.

Returns
  • get this element as a float.
Throws
NumberFormatException if the value contained is not a valid float.

public int getAsInt ()

convenience method to get this element as a primitive integer.

Returns
  • get this element as a primitive integer.
Throws
NumberFormatException if the value contained is not a valid integer.

public long getAsLong ()

convenience method to get this element as a primitive long.

Returns
  • get this element as a primitive long.
Throws
NumberFormatException if the value contained is not a valid long.

public Number getAsNumber ()

convenience method to get this element as a Number.

Returns
  • get this element as a Number.
Throws
NumberFormatException if the value contained is not a valid Number.

public short getAsShort ()

convenience method to get this element as a primitive short.

Returns
  • get this element as a primitive short.
Throws
NumberFormatException if the value contained is not a valid short value.

public String getAsString ()

convenience method to get this element as a String.

Returns
  • get this element as a String.

public int hashCode ()

public boolean isBoolean ()

Check whether this primitive contains a boolean value.

Returns
  • true if this primitive contains a boolean value, false otherwise.

public boolean isNumber ()

Check whether this primitive contains a Number.

Returns
  • true if this primitive contains a Number, false otherwise.

public boolean isString ()

Check whether this primitive contains a String value.

Returns
  • true if this primitive contains a String value, false otherwise.