public final class JsonPrimitive extends JsonElement
| Modifier and Type | Field and Description |
|---|---|
private static java.lang.Class<?>[] |
PRIMITIVE_TYPES |
private java.lang.Object |
value |
| Constructor and Description |
|---|
JsonPrimitive(java.lang.Boolean bool)
Create a primitive containing a boolean value.
|
JsonPrimitive(java.lang.Character c)
Create a primitive containing a character.
|
JsonPrimitive(java.lang.Number number)
Create a primitive containing a
Number. |
JsonPrimitive(java.lang.Object primitive)
Create a primitive using the specified Object.
|
JsonPrimitive(java.lang.String string)
Create a primitive containing a String value.
|
| Modifier and Type | Method and Description |
|---|---|
JsonPrimitive |
deepCopy()
Returns the same value as primitives are immutable.
|
boolean |
equals(java.lang.Object obj) |
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.
|
(package private) java.lang.Boolean |
getAsBooleanWrapper()
convenience method to get this element as a
Boolean. |
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.
|
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.
|
java.lang.String |
getAsString()
convenience method to get this element as a String.
|
int |
hashCode() |
boolean |
isBoolean()
Check whether this primitive contains a boolean value.
|
private static boolean |
isIntegral(JsonPrimitive primitive)
Returns true if the specified number is an integral type
(Long, Integer, Short, Byte, BigInteger)
|
boolean |
isNumber()
Check whether this primitive contains a Number.
|
private static boolean |
isPrimitiveOrString(java.lang.Object target) |
boolean |
isString()
Check whether this primitive contains a String value.
|
(package private) void |
setValue(java.lang.Object primitive) |
getAsJsonArray, getAsJsonNull, getAsJsonObject, getAsJsonPrimitive, isJsonArray, isJsonNull, isJsonObject, isJsonPrimitive, toStringprivate static final java.lang.Class<?>[] PRIMITIVE_TYPES
private java.lang.Object value
public JsonPrimitive(java.lang.Boolean bool)
bool - the value to create the primitive with.public JsonPrimitive(java.lang.Number number)
Number.number - the value to create the primitive with.public JsonPrimitive(java.lang.String string)
string - the value to create the primitive with.public JsonPrimitive(java.lang.Character c)
c - the value to create the primitive with.JsonPrimitive(java.lang.Object primitive)
Number, a
Java primitive type, or a String.primitive - the value to create the primitive with.public JsonPrimitive deepCopy()
deepCopy in class JsonElementvoid setValue(java.lang.Object primitive)
public boolean isBoolean()
java.lang.Boolean getAsBooleanWrapper()
Boolean.getAsBooleanWrapper in class JsonElementBoolean.public boolean getAsBoolean()
getAsBoolean in class JsonElementpublic boolean isNumber()
public java.lang.Number getAsNumber()
getAsNumber in class JsonElementjava.lang.NumberFormatException - if the value contained is not a valid Number.public boolean isString()
public java.lang.String getAsString()
getAsString in class JsonElementpublic double getAsDouble()
getAsDouble in class JsonElementjava.lang.NumberFormatException - if the value contained is not a valid double.public java.math.BigDecimal getAsBigDecimal()
BigDecimal.getAsBigDecimal in class JsonElementBigDecimal.java.lang.NumberFormatException - if the value contained is not a valid BigDecimal.public java.math.BigInteger getAsBigInteger()
BigInteger.getAsBigInteger in class JsonElementBigInteger.java.lang.NumberFormatException - if the value contained is not a valid BigInteger.public float getAsFloat()
getAsFloat in class JsonElementjava.lang.NumberFormatException - if the value contained is not a valid float.public long getAsLong()
getAsLong in class JsonElementjava.lang.NumberFormatException - if the value contained is not a valid long.public short getAsShort()
getAsShort in class JsonElementjava.lang.NumberFormatException - if the value contained is not a valid short value.public int getAsInt()
getAsInt in class JsonElementjava.lang.NumberFormatException - if the value contained is not a valid integer.public byte getAsByte()
JsonElementgetAsByte in class JsonElementpublic char getAsCharacter()
JsonElementgetAsCharacter in class JsonElementprivate static boolean isPrimitiveOrString(java.lang.Object target)
public int hashCode()
hashCode in class java.lang.Objectpublic boolean equals(java.lang.Object obj)
equals in class java.lang.Objectprivate static boolean isIntegral(JsonPrimitive primitive)