Package com.oorian.json
Class JsonValue
java.lang.Object
com.oorian.json.JsonValue
- Direct Known Subclasses:
JsonArray,JsonBoolean,JsonNull,JsonNumber,JsonObject,JsonString
Abstract base class for all JSON value types in the Oorian JSON library.
JsonValue serves as the root of the JSON type hierarchy, with concrete implementations
for each JSON data type: JsonObject, JsonArray, JsonString,
JsonNumber, JsonBoolean, and JsonNull.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionasArray()Casts this value to aJsonArray.Casts this value to aJsonBoolean.asNumber()Casts this value to aJsonNumber.asObject()Casts this value to aJsonObject.asString()Casts this value to aJsonString.booleanisArray()Returnstrueif this value is a JSON array.booleanisNumber()Returnstrueif this value is a JSON number.booleanisObject()Returnstrueif this value is a JSON object.booleanisString()Returnstrueif this value is a JSON string.static JsonValueParses a JSON string and returns the appropriate JsonValue subtype.abstract StringReturns this value serialized as a JSON string.toString()
-
Constructor Details
-
JsonValue
public JsonValue()
-
-
Method Details
-
parse
Parses a JSON string and returns the appropriate JsonValue subtype.- Parameters:
json- the JSON string to parse.- Returns:
- the parsed JsonValue.
-
isObject
public boolean isObject()Returnstrueif this value is a JSON object.- Returns:
trueif this is aJsonObject.
-
isArray
public boolean isArray()Returnstrueif this value is a JSON array.- Returns:
trueif this is aJsonArray.
-
isString
public boolean isString()Returnstrueif this value is a JSON string.- Returns:
trueif this is aJsonString.
-
isNumber
public boolean isNumber()Returnstrueif this value is a JSON number.- Returns:
trueif this is aJsonNumber.
-
asObject
Casts this value to aJsonObject.- Returns:
- this value as a JsonObject.
- Throws:
ClassCastException- if this value is not a JsonObject.
-
asArray
Casts this value to aJsonArray.- Returns:
- this value as a JsonArray.
- Throws:
ClassCastException- if this value is not a JsonArray.
-
asString
Casts this value to aJsonString.- Returns:
- this value as a JsonString.
- Throws:
ClassCastException- if this value is not a JsonString.
-
asNumber
Casts this value to aJsonNumber.- Returns:
- this value as a JsonNumber.
- Throws:
ClassCastException- if this value is not a JsonNumber.
-
asBoolean
Casts this value to aJsonBoolean.- Returns:
- this value as a JsonBoolean.
- Throws:
ClassCastException- if this value is not a JsonBoolean.
-
toString
-
toJsonString
Returns this value serialized as a JSON string.- Returns:
- the JSON string representation.
-