Interface JsonArray

All Superinterfaces:
JsonValue

public non-sealed interface JsonArray extends JsonValue
The interface that represents JSON array.

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

Alternatively, of(List) can be used to obtain a JsonArray.

Since:
28
External Specifications
  • Method Summary

    Modifier and Type
    Method
    Description
    Returns an unmodifiable list of the JsonValues if this JsonValue is an instance of JsonArray; 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.
    static JsonArray
    of(List<? extends JsonValue> src)
    Returns the JsonArray whose contents are copied from the given list of JsonValues.

    Methods declared in interface JsonValue

    asBoolean, asDouble, asInt, asLong, asMap, asString, get, toString, tryGet, tryValue
    Modifier and Type
    Method
    Description
    default boolean
    Returns the boolean value represented by this JsonValue if it is an instance of JsonBoolean; otherwise, throws a JsonValueException.
    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 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(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

    • asList

      List<JsonValue> asList()
      Returns an unmodifiable list of the JsonValues if this JsonValue is an instance of JsonArray; otherwise, throws a JsonValueException.
      Specified by:
      asList in interface JsonValue
      Returns:
      an unmodifiable list of the JsonValues if this JsonValue is an instance of JsonArray; otherwise, throws a JsonValueException
    • get

      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.
      Specified by:
      get in interface JsonValue
      Parameters:
      index - the index of the array
      Returns:
      the JsonValue associated with the given index if this JsonValue is an instance of JsonArray; otherwise, throws a JsonValueException
      Throws:
      JsonValueException - if the given index is out of bounds
    • of

      static JsonArray of(List<? extends JsonValue> src)
      Returns the JsonArray whose contents are copied from the given list of JsonValues.
      Parameters:
      src - the list of JsonValues. Non-null.
      Returns:
      the JsonArray whose contents are copied from the given list of JsonValues
      Throws:
      NullPointerException - if src is null, or contains any values that are null