Package javax.json

Interface JsonArrayBuilder


  • public interface JsonArrayBuilder
    A builder for creating JsonArray models from scratch, and for modifying a existing JsonArray.

    This is a near-exact copy of the same-titled Java EE 8 Class: javax.json.JsonArrayBuilder
    Commenting has been slightly modified to accompany HiLiting the Code Examples.
    Java Source Code remains identical to the Sun-Oracle & 'GlassFish' Released Distributions.

    Read included License: HERE, and the CDDL+GPL-1.1
    All javax.json.* Code Obtained From: GitHub JavaEE jsonp  Public Archive.


    A JsonArrayBuilder can start with an empty or a non-empty JSON array model. This interface provides methods to add, insert, remove and replace values in the JSON array model.

    Methods in this class can be chained to perform multiple values to the array.

    The class Json contains methods to create the builder object. The example code below shows how to build an empty JsonArray instance.

     JsonArray array = Json.createArrayBuilder().build();
    


    The class JsonBuilderFactory also contains methods to create JsonArrayBuilder instances. A factory instance can be used to create multiple builder instances with the same configuration. This the preferred way to create multiple instances.

    The example code below shows how to build a JsonArray object that represents the following JSON array:

    Java Script Object Notation (JSON):
     [
         { "type": "home", "number": "212 555-1234" },
         { "type": "fax", "number": "646 555-4567" }
     ]
    

    The following code creates the JSON array above:

    Example:
     JsonBuilderFactory factory = Json.createBuilderFactory(config);
     
     JsonArray value = factory
          .createArrayBuilder()
          .add(factory.createObjectBuilder()
              .add("type", "home")
              .add("number", "212 555-1234"))
          .add(factory.createObjectBuilder()
              .add("type", "fax")
              .add("number", "646 555-4567"))
          .build();
    

    This class does not allow null to be used as a value while building the JSON array
    See Also:
    JsonObjectBuilder


    • Method Detail

      • add

        🡅  🡇     🗕  🗗  🗖
        JsonArrayBuilder add​(java.lang.String value)
        Adds a value to the array as a JsonString.
        Parameters:
        value - the string value
        Returns:
        this array builder
        Throws:
        java.lang.NullPointerException - if the specified value is null
      • addAll

        🡅  🡇     🗕  🗗  🗖
        default JsonArrayBuilder addAll​(JsonArrayBuilder builder)
        Adds all elements of the array in the specified array builder to the array.
        Parameters:
        builder - the array builder
        Returns:
        this array builder
        Throws:
        java.lang.NullPointerException - if the specified builder is null
        Since:
        1.1
        Code:
        Exact Method Body:
         throw new UnsupportedOperationException();
        
      • add

        🡅  🡇     🗕  🗗  🗖
        default JsonArrayBuilder add​(int index,
                                     JsonValue value)
        Inserts a value to the array at the specified position. Shifts the value currently at that position (if any) and any subsequent values to the right (adds one to their indices). Index starts with 0.
        Parameters:
        index - the position in the array
        value - the JSON value
        Returns:
        this array builder
        Throws:
        java.lang.NullPointerException - if the specified value is null
        java.lang.IndexOutOfBoundsException - if the index is out of range (index < 0 || index > array size)
        Since:
        1.1
        Code:
        Exact Method Body:
         throw new UnsupportedOperationException();
        
      • add

        🡅  🡇     🗕  🗗  🗖
        default JsonArrayBuilder add​(int index,
                                     java.lang.String value)
        Adds a value to the array as a JsonString at the specified position. Shifts the value currently at that position (if any) and any subsequent values to the right (adds one to their indices). Index starts with 0.
        Parameters:
        index - the position in the array
        value - the string value
        Returns:
        this array builder
        Throws:
        java.lang.NullPointerException - if the specified value is null
        java.lang.IndexOutOfBoundsException - if the index is out of range (index < 0 || index > array size)
        Since:
        1.1
        Code:
        Exact Method Body:
         throw new UnsupportedOperationException();
        
      • add

        🡅  🡇     🗕  🗗  🗖
        default JsonArrayBuilder add​(int index,
                                     java.math.BigDecimal value)
        Adds a value to the array as a JsonNumber at the specified position. Shifts the value currently at that position (if any) and any subsequent values to the right (adds one to their indices). Index starts with 0.
        Parameters:
        index - the position in the array
        value - the number value
        Returns:
        this array builder
        Throws:
        java.lang.NullPointerException - if the specified value is null
        java.lang.IndexOutOfBoundsException - if the index is out of range (index < 0 || index > array size)
        Since:
        1.1
        See Also:
        JsonNumber
        Code:
        Exact Method Body:
         throw new UnsupportedOperationException();
        
      • add

        🡅  🡇     🗕  🗗  🗖
        default JsonArrayBuilder add​(int index,
                                     java.math.BigInteger value)
        Adds a value to the array as a JsonNumber at the specified position. Shifts the value currently at that position (if any) and any subsequent values to the right (adds one to their indices). Index starts with 0.
        Parameters:
        index - the position in the array
        value - the number value
        Returns:
        this array builder
        Throws:
        java.lang.NullPointerException - if the specified value is null
        java.lang.IndexOutOfBoundsException - if the index is out of range (index < 0 || index > array size)
        Since:
        1.1
        See Also:
        JsonNumber
        Code:
        Exact Method Body:
         throw new UnsupportedOperationException();
        
      • add

        🡅  🡇     🗕  🗗  🗖
        default JsonArrayBuilder add​(int index,
                                     int value)
        Adds a value to the array as a JsonNumber at the specified position. Shifts the value currently at that position (if any) and any subsequent values to the right (adds one to their indices). Index starts with 0.
        Parameters:
        index - the position in the array
        value - the number value
        Returns:
        this array builder
        Throws:
        java.lang.IndexOutOfBoundsException - if the index is out of range (index < 0 || index > array size)
        Since:
        1.1
        See Also:
        JsonNumber
        Code:
        Exact Method Body:
         throw new UnsupportedOperationException();
        
      • add

        🡅  🡇     🗕  🗗  🗖
        default JsonArrayBuilder add​(int index,
                                     long value)
        Adds a value to the array as a JsonNumber at the specified position. Shifts the value currently at that position (if any) and any subsequent values to the right (adds one to their indices). Index starts with 0.
        Parameters:
        index - the position in the array
        value - the number value
        Returns:
        this array builder
        Throws:
        java.lang.IndexOutOfBoundsException - if the index is out of range (index < 0 || index > array size)
        Since:
        1.1
        See Also:
        JsonNumber
        Code:
        Exact Method Body:
         throw new UnsupportedOperationException();
        
      • add

        🡅  🡇     🗕  🗗  🗖
        default JsonArrayBuilder add​(int index,
                                     double value)
        Adds a value to the array as a JsonNumber at the specified position. Shifts the value currently at that position (if any) and any subsequent values to the right (adds one to their indices). Index starts with 0.
        Parameters:
        index - the position in the array
        value - the number value
        Returns:
        this array builder
        Throws:
        java.lang.NumberFormatException - if the value is Not-a-Number (NaN) or infinity
        java.lang.IndexOutOfBoundsException - if the index is out of range (index < 0 || index > array size)
        Since:
        1.1
        See Also:
        JsonNumber
        Code:
        Exact Method Body:
         throw new UnsupportedOperationException();
        
      • add

        🡅  🡇     🗕  🗗  🗖
        default JsonArrayBuilder add​(int index,
                                     boolean value)
        Adds a JsonValue.TRUE or JsonValue.FALSE value to the array at the specified position. Shifts the value currently at that position (if any) and any subsequent values to the right (adds one to their indices). Index starts with 0.
        Parameters:
        index - the position in the array
        value - the boolean value
        Returns:
        this array builder
        Throws:
        java.lang.IndexOutOfBoundsException - if the index is out of range (index < 0 || index > array size)
        Since:
        1.1
        Code:
        Exact Method Body:
         throw new UnsupportedOperationException();
        
      • addNull

        🡅  🡇     🗕  🗗  🗖
        default JsonArrayBuilder addNull​(int index)
        Adds a JsonValue.NULL value to the array at the specified position. Shifts the value currently at that position (if any) and any subsequent values to the right (adds one to their indices). Index starts with 0.
        Parameters:
        index - the position in the array
        Returns:
        this array builder
        Throws:
        java.lang.IndexOutOfBoundsException - if the index is out of range (index < 0 || index > array size)
        Since:
        1.1
        Code:
        Exact Method Body:
         return add(index, JsonValue.NULL);
        
      • add

        🡅  🡇     🗕  🗗  🗖
        default JsonArrayBuilder add​(int index,
                                     JsonObjectBuilder builder)
        Adds a JsonObject from an object builder to the array at the specified position. Shifts the value currently at that position (if any) and any subsequent values to the right (adds one to their indices). Index starts with 0.
        Parameters:
        index - the position in the array
        builder - the object builder
        Returns:
        this array builder
        Throws:
        java.lang.NullPointerException - if the specified builder is null
        java.lang.IndexOutOfBoundsException - if the index is out of range (index < 0 || index > array size)
        Since:
        1.1
        Code:
        Exact Method Body:
         throw new UnsupportedOperationException();
        
      • add

        🡅  🡇     🗕  🗗  🗖
        default JsonArrayBuilder add​(int index,
                                     JsonArrayBuilder builder)
        Adds a JsonArray from an array builder to the array at the specified position. Shifts the value currently at that position (if any) and any subsequent values to the right (adds one to their indices). Index starts with 0.
        Parameters:
        index - the position in the array
        builder - the array builder
        Returns:
        this array builder
        Throws:
        java.lang.NullPointerException - if the specified builder is null
        java.lang.IndexOutOfBoundsException - if the index is out of range (index < 0 || index > array size)
        Since:
        1.1
        Code:
        Exact Method Body:
         throw new UnsupportedOperationException();
        
      • set

        🡅  🡇     🗕  🗗  🗖
        default JsonArrayBuilder set​(int index,
                                     JsonValue value)
        Replaces a value in the array with the specified value at the specified position.
        Parameters:
        index - the position in the array
        value - the JSON value
        Returns:
        this array builder
        Throws:
        java.lang.NullPointerException - if the specified value is null
        java.lang.IndexOutOfBoundsException - if the index is out of range (index < 0 || index >= array size)
        Since:
        1.1
        Code:
        Exact Method Body:
         throw new UnsupportedOperationException();
        
      • set

        🡅  🡇     🗕  🗗  🗖
        default JsonArrayBuilder set​(int index,
                                     java.lang.String value)
        Replaces a value in the array with the specified value as a JsonString at the specified position.
        Parameters:
        index - the position in the array
        value - the string value
        Returns:
        this array builder
        Throws:
        java.lang.NullPointerException - if the specified value is null
        java.lang.IndexOutOfBoundsException - if the index is out of range (index < 0 || index >= array size)
        Since:
        1.1
        Code:
        Exact Method Body:
         throw new UnsupportedOperationException();
        
      • set

        🡅  🡇     🗕  🗗  🗖
        default JsonArrayBuilder set​(int index,
                                     java.math.BigDecimal value)
        Replaces a value in the array with the specified value as a JsonNumber at the specified position.
        Parameters:
        index - the position in the array
        value - the number value
        Returns:
        this array builder
        Throws:
        java.lang.NullPointerException - if the specified value is null
        java.lang.IndexOutOfBoundsException - if the index is out of range (index < 0 || index >= array size)
        Since:
        1.1
        See Also:
        JsonNumber
        Code:
        Exact Method Body:
         throw new UnsupportedOperationException();
        
      • set

        🡅  🡇     🗕  🗗  🗖
        default JsonArrayBuilder set​(int index,
                                     java.math.BigInteger value)
        Replaces a value in the array with the specified value as a JsonNumber at the specified position.
        Parameters:
        index - the position in the array
        value - the number value
        Returns:
        this array builder
        Throws:
        java.lang.NullPointerException - if the specified value is null
        java.lang.IndexOutOfBoundsException - if the index is out of range (index < 0 || index >= array size)
        Since:
        1.1
        See Also:
        JsonNumber
        Code:
        Exact Method Body:
         throw new UnsupportedOperationException();
        
      • set

        🡅  🡇     🗕  🗗  🗖
        default JsonArrayBuilder set​(int index,
                                     int value)
        Replaces a value in the array with the specified value as a JsonNumber at the specified position.
        Parameters:
        index - the position in the array
        value - the number value
        Returns:
        this array builder
        Throws:
        java.lang.IndexOutOfBoundsException - if the index is out of range (index < 0 || index >= array size)
        Since:
        1.1
        See Also:
        JsonNumber
        Code:
        Exact Method Body:
         throw new UnsupportedOperationException();
        
      • set

        🡅  🡇     🗕  🗗  🗖
        default JsonArrayBuilder set​(int index,
                                     long value)
        Replaces a value in the array with the specified value as a JsonNumber at the specified position.
        Parameters:
        index - the position in the array
        value - the number value
        Returns:
        this array builder
        Throws:
        java.lang.IndexOutOfBoundsException - if the index is out of range (index < 0 || index >= array size)
        Since:
        1.1
        See Also:
        JsonNumber
        Code:
        Exact Method Body:
         throw new UnsupportedOperationException();
        
      • set

        🡅  🡇     🗕  🗗  🗖
        default JsonArrayBuilder set​(int index,
                                     double value)
        Replaces a value in the array with the specified value as a JsonNumber at the specified position.
        Parameters:
        index - the position in the array
        value - the number value
        Returns:
        this array builder
        Throws:
        java.lang.NumberFormatException - if the value is Not-a-Number (NaN) or infinity
        java.lang.IndexOutOfBoundsException - if the index is out of range (index < 0 || index >= array size)
        Since:
        1.1
        See Also:
        JsonNumber
        Code:
        Exact Method Body:
         throw new UnsupportedOperationException();
        
      • set

        🡅  🡇     🗕  🗗  🗖
        default JsonArrayBuilder set​(int index,
                                     boolean value)
        Replaces a value in the array with a JsonValue.TRUE or JsonValue.FALSE value at the specified position.
        Parameters:
        index - the position in the array
        value - the boolean value
        Returns:
        this array builder
        Throws:
        java.lang.IndexOutOfBoundsException - if the index is out of range (index < 0 || index >= array size)
        Since:
        1.1
        Code:
        Exact Method Body:
         throw new UnsupportedOperationException();
        
      • setNull

        🡅  🡇     🗕  🗗  🗖
        default JsonArrayBuilder setNull​(int index)
        Replaces a value in the array with a JsonValue.NULL value at the specified position.
        Parameters:
        index - the position in the array
        Returns:
        this array builder
        Throws:
        java.lang.IndexOutOfBoundsException - if the index is out of range (index < 0 || index >= array size)
        Since:
        1.1
        Code:
        Exact Method Body:
         return set(index, JsonValue.NULL);
        
      • set

        🡅  🡇     🗕  🗗  🗖
        default JsonArrayBuilder set​(int index,
                                     JsonObjectBuilder builder)
        Replaces a value in the array with the specified value as a JsonObject from an object builder at the specified position.
        Parameters:
        index - the position in the array
        builder - the object builder
        Returns:
        this array builder
        Throws:
        java.lang.NullPointerException - if the specified builder is null
        java.lang.IndexOutOfBoundsException - if the index is out of range (index < 0 || index >= array size)
        Since:
        1.1
        Code:
        Exact Method Body:
         throw new UnsupportedOperationException();
        
      • set

        🡅  🡇     🗕  🗗  🗖
        default JsonArrayBuilder set​(int index,
                                     JsonArrayBuilder builder)
        Replaces a value in the array with the specified value as a JsonArray from an array builder at the specified position.
        Parameters:
        index - the position in the array
        builder - the array builder
        Returns:
        this array builder
        Throws:
        java.lang.NullPointerException - if the specified builder is null
        java.lang.IndexOutOfBoundsException - if the index is out of range (index < 0 || index >= array size)
        Since:
        1.1
        Code:
        Exact Method Body:
         throw new UnsupportedOperationException();
        
      • remove

        🡅  🡇     🗕  🗗  🗖
        default JsonArrayBuilder remove​(int index)
        Remove the value in the array at the specified position. Shift any subsequent values to the left (subtracts one from their indices.
        Parameters:
        index - the position in the array
        Returns:
        this array builder
        Throws:
        java.lang.IndexOutOfBoundsException - if the index is out of range (index < 0 || index >= array size)
        Since:
        1.1
        Code:
        Exact Method Body:
         throw new UnsupportedOperationException();