Class JsonElement
- java.lang.Object
-
- com.github.mavolin.maxon.jsonvalues.JsonElement
-
public class JsonElement extends Object
AJsonElement
is the Object used byJsonArrays
andJsonObjects
in their respective collections, to make the use of the enhanced for loop more easy to use. To do soJsonElement
containsgetAsX()
methods to prevent the need of casting on the user end.
-
-
Constructor Summary
Constructors Constructor Description JsonElement(JsonValue value)
Creates a newJsonElement
holding the passedJsonValue
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(Object o)
Checks, whether or not thisJsonElement
is equal to the providedObject o
.BigDecimal
getAsBigDecimal()
Gets thisJsonElement
as aBigDecimal
.BigInteger
getAsBigInteger()
Gets thisJsonElement
as aBigInteger
.Boolean
getAsBoolean()
Gets thisJsonElement
as aBoolean
.Byte
getAsByte()
Gets thisJsonElement
as aByte
.Character
getAsCharacter()
Gets thisJsonElement
as aCharacter
.Double
getAsDouble()
Gets thisJsonElement
as aDouble
.Float
getAsFloat()
Gets thisJsonElement
as aFloat
.Integer
getAsInteger()
Gets thisJsonElement
as anInteger
.JsonArray
getAsJsonArray()
Gets thisJsonElement
as aJsonArray
.JsonObject
getAsJsonObject()
Gets thisJsonElement
as aJsonObject
.JsonValue
getAsJsonValue()
Gets thisJsonElement
as aJsonValue
.Long
getAsLong()
Gets thisJsonElement
as aLong
.Short
getAsShort()
Gets thisJsonElement
as aShort
.String
getAsString()
Gets thisJsonElement
as aString
.int
hashCode()
Generates a hash code that is unique to every object, that is not equal to one another, as defined byequals(Object)
, but is the same for everyJsonElement
that is equal.boolean
isBoolean()
Checks if theJsonElement
represents aboolean
.boolean
isCharacter()
Checks if theJsonElement
represents acharacter
.boolean
isJsonArray()
Checks if theJsonElement
represents aJsonArray
.boolean
isJsonObject()
Checks if theJsonElement
represents aJsonObject
.boolean
isNull()
Checks if theJsonElement
is JSON nullboolean
isNumber()
Checks if theJsonElement
represents aNumber
.boolean
isString()
Checks if theJsonElement
represents aString
.String
toString()
Returns aString
representation of thisJsonElement
.
-
-
-
Method Detail
-
isNull
public boolean isNull()
Checks if theJsonElement
is JSON null- Returns:
true
if theJsonElement
is null;false
otherwise
-
isBoolean
public boolean isBoolean()
Checks if theJsonElement
represents aboolean
.- Returns:
true
if theJsonElement
represents aboolean
;false
otherwise
-
isCharacter
public boolean isCharacter()
Checks if theJsonElement
represents acharacter
.- Returns:
true
if theJsonElement
represents acharacter
;false
otherwise
-
isNumber
public boolean isNumber()
Checks if theJsonElement
represents aNumber
.- Returns:
true
if theJsonElement
represents aNumber
;false
otherwise
-
isString
public boolean isString()
Checks if theJsonElement
represents aString
.- Returns:
true
if theJsonElement
represents aString
;false
otherwise
-
isJsonArray
public boolean isJsonArray()
Checks if theJsonElement
represents aJsonArray
.- Returns:
true
if theJsonElement
represents aJsonArray
;false
otherwise
-
isJsonObject
public boolean isJsonObject()
Checks if theJsonElement
represents aJsonObject
.- Returns:
true
if theJsonElement
represents aJsonObject
;false
otherwise
-
getAsBoolean
public Boolean getAsBoolean()
Gets thisJsonElement
as aBoolean
.- Returns:
- the
Boolean
- Throws:
IllegalTypeRequestedException
- if thisJsonElement's
value is not an instance ofBoolean
-
getAsCharacter
public Character getAsCharacter()
Gets thisJsonElement
as aCharacter
.- Returns:
- the
Character
- Throws:
IllegalTypeRequestedException
- if thisJsonElement's
value is not an instance ofCharacter
-
getAsByte
public Byte getAsByte()
Gets thisJsonElement
as aByte
.- Returns:
- the
Byte
- Throws:
IllegalTypeRequestedException
- if thisJsonElement's
value is not an instance ofByte
-
getAsShort
public Short getAsShort()
Gets thisJsonElement
as aShort
.- Returns:
- the
Short
- Throws:
IllegalTypeRequestedException
- if thisJsonElement's
value is not an instance ofShort
-
getAsInteger
public Integer getAsInteger()
Gets thisJsonElement
as anInteger
.- Returns:
- the
Integer
- Throws:
IllegalTypeRequestedException
- if thisJsonElement's
value is not an instance ofInteger
-
getAsLong
public Long getAsLong()
Gets thisJsonElement
as aLong
.- Returns:
- the
Long
- Throws:
IllegalTypeRequestedException
- if thisJsonElement's
value is not an instance ofLong
-
getAsBigInteger
public BigInteger getAsBigInteger()
Gets thisJsonElement
as aBigInteger
.- Returns:
- the
BigInteger
- Throws:
IllegalTypeRequestedException
- if thisJsonElement's
value is not an instance ofBigInteger
-
getAsFloat
public Float getAsFloat()
Gets thisJsonElement
as aFloat
.- Returns:
- the
Float
- Throws:
IllegalTypeRequestedException
- if thisJsonElement's
value is not an instance ofFloat
-
getAsDouble
public Double getAsDouble()
Gets thisJsonElement
as aDouble
.- Returns:
- the
Double
- Throws:
IllegalTypeRequestedException
- if thisJsonElement's
value is not an instance ofDouble
-
getAsBigDecimal
public BigDecimal getAsBigDecimal()
Gets thisJsonElement
as aBigDecimal
.- Returns:
- the
BigDecimal
- Throws:
IllegalTypeRequestedException
- if thisJsonElement's
value is not an instance ofBigDecimal
-
getAsString
public String getAsString()
Gets thisJsonElement
as aString
.- Returns:
- the
String
- Throws:
IllegalTypeRequestedException
- if thisJsonElement's
value is not an instance ofString
-
getAsJsonArray
public JsonArray getAsJsonArray()
Gets thisJsonElement
as aJsonArray
.- Returns:
- the
JsonArray
- Throws:
IllegalTypeRequestedException
- if thisJsonElement's
value is not an instance ofJsonArray
-
getAsJsonObject
public JsonObject getAsJsonObject()
Gets thisJsonElement
as aJsonObject
.- Returns:
- the
JsonObject
- Throws:
IllegalTypeRequestedException
- if thisJsonElement's
value is not an instance ofJsonObject
-
getAsJsonValue
public JsonValue getAsJsonValue()
Gets thisJsonElement
as aJsonValue
.- Returns:
- the
JsonOValue
- Throws:
IllegalTypeRequestedException
- if thisJsonElement's
value is not an instance ofJsonValue
-
equals
public boolean equals(Object o)
Checks, whether or not thisJsonElement
is equal to the providedObject o
.
-
hashCode
public int hashCode()
Generates a hash code that is unique to every object, that is not equal to one another, as defined byequals(Object)
, but is the same for everyJsonElement
that is equal.
-
-