Class JsonValue

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

public abstract sealed class JsonValue extends Object permits JsonArray, JsonBoolean, JsonNull, JsonNumber, JsonObject, JsonString (not exhaustive)
Base class for all JSON value types in Helidon JSON processing.

This module is incubating. These APIs may change in any version of Helidon, including backward incompatible changes.

  • Method Details

    • objectBuilder

      public static JsonObject.Builder objectBuilder()
      A new fluent API builder to construct an JsonObject.
      Returns:
      a new builder
    • type

      public abstract JsonValueType type()
      Return the type of this JSON value.
      Returns:
      the JsonValueType of this value
    • toJson

      public abstract void toJson(JsonGenerator generator)
      Write this JSON value to the provided generator.
      Parameters:
      generator - the generator to write to
    • toString

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

      public JsonString asString()
      Cast this value to a JsonString if it is of string type.
      Returns:
      this value as a JsonString
      Throws:
      JsonException - if this value is not a string
    • asNumber

      public JsonNumber asNumber()
      Cast this value to a JsonNumber if it is of number type.
      Returns:
      this value as a JsonNumber
      Throws:
      JsonException - if this value is not a number
    • asObject

      public JsonObject asObject()
      Cast this value to a JsonObject if it is of object type.
      Returns:
      this value as a JsonObject
      Throws:
      JsonException - if this value is not an object
    • asArray

      public JsonArray asArray()
      Cast this value to a JsonArray if it is of array type.
      Returns:
      this value as a JsonArray
      Throws:
      JsonException - if this value is not an array
    • asBoolean

      public JsonBoolean asBoolean()
      Cast this value to a JsonBoolean if it is of boolean type.
      Returns:
      this value as a JsonBoolean
      Throws:
      JsonException - if this value is not a boolean