Interface JsonBoolean

All Superinterfaces:
JsonValue

public non-sealed interface JsonBoolean extends JsonValue
The interface that represents the JSON boolean literals, "true" and "false".

A JsonBoolean can be created by parsing JSON text using either Json.parse(String) or Json.parse(char[]).

Alternatively, of(boolean) can be used to obtain a JsonBoolean.

Since:
28
External Specifications
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Returns the boolean value represented by this JsonValue if it is an instance of JsonBoolean; otherwise, throws a JsonValueException.
    of(boolean src)
    Returns the JsonBoolean created from the given boolean.

    Methods declared in interface JsonValue

    asDouble, asInt, asList, asLong, asMap, asString, get, get, toString, tryGet, tryValue
    Modifier and Type
    Method
    Description
    default double
    Returns a double if this JsonValue is an instance of JsonNumber that can be converted, as if by Double.parseDouble, to a finite double value; otherwise, throws a JsonValueException.
    default int
    Returns an int if this JsonValue is an instance of JsonNumber that can be converted exactly; otherwise, throws a JsonValueException.
    default List<JsonValue>
    Returns an unmodifiable list of the JsonValues if this JsonValue is an instance of JsonArray; otherwise, throws a JsonValueException.
    default long
    Returns a long if this JsonValue is an instance of JsonNumber that can be converted exactly; otherwise, throws a JsonValueException.
    default Map<String, JsonValue>
    Returns an unmodifiable map of String to JsonValue if this JsonValue is an instance of JsonObject; otherwise, throws a JsonValueException.
    default String
    Returns the String value represented by this JsonValue if it is an instance of JsonString; otherwise, throws a JsonValueException.
    default JsonValue
    get(int index)
    Returns the JsonValue associated with the given index if this JsonValue is an instance of JsonArray; otherwise, throws a JsonValueException.
    default JsonValue
    get(String name)
    Returns the JsonValue associated with the given member name if this JsonValue is an instance of JsonObject; otherwise, throws a JsonValueException.
    Returns a String representation of this JsonValue that conforms to JSON syntax.
    tryGet(String name)
    Returns an Optional containing the value of a given member of this JsonObject, or an empty Optional if the member is absent; throws JsonValueException if this JsonValue is not a JsonObject.
    Returns an Optional containing this JsonValue if it is not an instance of JsonNull, otherwise an empty Optional.
  • Method Details

    • asBoolean

      boolean asBoolean()
      Returns the boolean value represented by this JsonValue if it is an instance of JsonBoolean; otherwise, throws a JsonValueException.
      Specified by:
      asBoolean in interface JsonValue
      Returns:
      the boolean value represented by this JsonValue if it is an instance of JsonBoolean; otherwise, throws a JsonValueException
    • of

      static JsonBoolean of(boolean src)
      Returns the JsonBoolean created from the given boolean.
      Parameters:
      src - the given boolean.
      Returns:
      the JsonBoolean created from the given boolean