Class JsonValue

java.lang.Object
com.oorian.json.JsonValue
Direct Known Subclasses:
JsonArray, JsonBoolean, JsonNull, JsonNumber, JsonObject, JsonString

public abstract class JsonValue extends Object
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 Details

    • JsonValue

      public JsonValue()
  • Method Details

    • parse

      public static JsonValue parse(String json)
      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()
      Returns true if this value is a JSON object.
      Returns:
      true if this is a JsonObject.
    • isArray

      public boolean isArray()
      Returns true if this value is a JSON array.
      Returns:
      true if this is a JsonArray.
    • isString

      public boolean isString()
      Returns true if this value is a JSON string.
      Returns:
      true if this is a JsonString.
    • isNumber

      public boolean isNumber()
      Returns true if this value is a JSON number.
      Returns:
      true if this is a JsonNumber.
    • asObject

      public JsonObject asObject()
      Casts this value to a JsonObject.
      Returns:
      this value as a JsonObject.
      Throws:
      ClassCastException - if this value is not a JsonObject.
    • asArray

      public JsonArray asArray()
      Casts this value to a JsonArray.
      Returns:
      this value as a JsonArray.
      Throws:
      ClassCastException - if this value is not a JsonArray.
    • asString

      public JsonString asString()
      Casts this value to a JsonString.
      Returns:
      this value as a JsonString.
      Throws:
      ClassCastException - if this value is not a JsonString.
    • asNumber

      public JsonNumber asNumber()
      Casts this value to a JsonNumber.
      Returns:
      this value as a JsonNumber.
      Throws:
      ClassCastException - if this value is not a JsonNumber.
    • asBoolean

      public JsonBoolean asBoolean()
      Casts this value to a JsonBoolean.
      Returns:
      this value as a JsonBoolean.
      Throws:
      ClassCastException - if this value is not a JsonBoolean.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • toJsonString

      public abstract String toJsonString()
      Returns this value serialized as a JSON string.
      Returns:
      the JSON string representation.