Package javax.json

Interface JsonArray

    • Method Detail

      • getJsonObject

        JsonObject getJsonObject​(int index)
        Returns:
        the JsonObject at the given position
        Throws:
        java.lang.IndexOutOfBoundsException - if the index is out of range
        java.lang.ClassCastException - if the value at the specified position is not assignable to the JsonObject
      • getJsonArray

        JsonArray getJsonArray​(int index)
        Returns:
        the JsonArray at the given position
        Throws:
        java.lang.IndexOutOfBoundsException - if the index is out of range
        java.lang.ClassCastException - if the value at the specified position is not assignable to the JsonArray
      • getJsonNumber

        JsonNumber getJsonNumber​(int index)
        Returns:
        the JsonNumber at the given position
        Throws:
        java.lang.IndexOutOfBoundsException - if the index is out of range
        java.lang.ClassCastException - if the value at the specified position is not assignable to the JsonNumber
      • getJsonString

        JsonString getJsonString​(int index)
        Returns:
        the JsonString at the given position
        Throws:
        java.lang.IndexOutOfBoundsException - if the index is out of range
        java.lang.ClassCastException - if the value at the specified position is not assignable to the JsonString
      • getValuesAs

        <T extends JsonValue> java.util.List<T> getValuesAs​(java.lang.Class<T> clazz)
        Returns:
        the respective JsonValue at the given position
        Throws:
        java.lang.IndexOutOfBoundsException - if the index is out of range
        java.lang.ClassCastException - if the value at the specified position is not assignable to the given slazz
      • getValuesAs

        default <T,​K extends JsonValue> java.util.List<T> getValuesAs​(java.util.function.Function<K,​T> func)
        Returns a list for the array. The value and the type of the elements in the list is specified by the func argument.

        This method can be used to obtain a list of the unwrapped types, such as

        
             List<String> strings = ary1.getValuesAs(JsonString::getString);
             List<Integer> ints = ary2.getValuesAs(JsonNumber::intValue);
          
        It can also be used to obtain a list of simple projections, such as
         
             Lsit<Integer> stringsizes = arr.getValueAs((JsonString v) -> v.getString().length();
          
        Type Parameters:
        K - The element type (must be a subtype of JsonValue) of this JsonArray.
        T - The element type of the returned List
        Parameters:
        func - The function that maps the elements of this JsonArray to the target elements.
        Returns:
        A List of the specified values and type.
        Throws:
        java.lang.ClassCastException - if the JsonArray contains a value of wrong type
      • getString

        java.lang.String getString​(int index)
        Returns:
        the native String at the given position
        Throws:
        java.lang.IndexOutOfBoundsException - if the index is out of range
        java.lang.ClassCastException - if the value at the specified position is not assignable to a String
      • getString

        java.lang.String getString​(int index,
                                   java.lang.String defaultValue)
        Returns:
        the native String at the given position or the defaultValue if null
        Throws:
        java.lang.IndexOutOfBoundsException - if the index is out of range
        java.lang.ClassCastException - if the value at the specified position is not assignable to a String
      • getInt

        int getInt​(int index)
        Returns:
        the native int value at the given position
        Throws:
        java.lang.IndexOutOfBoundsException - if the index is out of range
        java.lang.ClassCastException - if the value at the specified position is not assignable to an int
        java.lang.NullPointerException - if an object with the given name doesn't exist
      • getInt

        int getInt​(int index,
                   int defaultValue)
        Returns:
        the native int value at the given position or the defaultValue if null
        Throws:
        java.lang.IndexOutOfBoundsException - if the index is out of range
        java.lang.ClassCastException - if the value at the specified position is not assignable to an int
      • getBoolean

        boolean getBoolean​(int index)
        Returns:
        the native boolean value at the given position
        Throws:
        java.lang.IndexOutOfBoundsException - if the index is out of range
        java.lang.ClassCastException - if the value at the specified position is not assignable to a boolean
        java.lang.NullPointerException - if an object with the given name doesn't exist
      • getBoolean

        boolean getBoolean​(int index,
                           boolean defaultValue)
        Returns:
        the native boolean value at the given position or the defaultValue if null
        Throws:
        java.lang.IndexOutOfBoundsException - if the index is out of range
        java.lang.ClassCastException - if the value at the specified position is not assignable to a boolean
      • isNull

        boolean isNull​(int index)
        Returns:
        whether the value at the given position is JsonValue.NULL.
        Throws:
        java.lang.IndexOutOfBoundsException - if the index is out of range