io.vertx.core.json

## Class JsonArray

- java.lang.Object
- - io.vertx.core.json.JsonArray

- All Implemented Interfaces:
    io.vertx.core.shareddata.impl.ClusterSerializable, Iterable<Object>

      public class JsonArray
      extends Object
      implements Iterable<Object>, io.vertx.core.shareddata.impl.ClusterSerializable

  A representation of a JSON array in Java.

  Unlike some other languages Java does not have a native understanding of JSON. To enable JSON to be used easily in Vert.x code we use this class to encapsulate the notion of a JSON array.

  Please see the documentation for more information.

  Author:
    Tim Fox

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `JsonArray()` Create an empty instance
    `JsonArray(List list)` Create an instance from a List.
    `JsonArray(String json)` Create an instance from a String of JSON

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `JsonArray` | `add(Boolean value)` Add a Boolean to the JSON array.
    `JsonArray` | `add(byte[] value)` Add a binary value to the JSON array.
    `JsonArray` | `add(CharSequence value)` Add a CharSequence to the JSON array.
    `JsonArray` | `add(Double value)` Add a Double to the JSON array.
    `JsonArray` | `add(Enum value)` Add an enum to the JSON array.
    `JsonArray` | `add(Float value)` Add a Float to the JSON array.
    `JsonArray` | `add(Integer value)` Add an Integer to the JSON array.
    `JsonArray` | `add(JsonArray value)` Add another JSON array to the JSON array.
    `JsonArray` | `add(JsonObject value)` Add a JSON object to the JSON array.
    `JsonArray` | `add(Long value)` Add a Long to the JSON array.
    `JsonArray` | `add(Object value)` Add an Object to the JSON array.
    `JsonArray` | `add(String value)` Add a String to the JSON array.
    `JsonArray` | `addAll(JsonArray array)` Appends all of the elements in the specified array to the end of this JSON array.
    `JsonArray` | `addNull()` Add a null value to the JSON array.
    `JsonArray` | `clear()` Remove all entries from the JSON array
    `boolean` | `contains(Object value)` Does the JSON array contain the specified value? This method will scan the entire array until it finds a value or reaches the end.
    `JsonArray` | `copy()` Make a copy of the JSON array
    `String` | `encode()` Encode the JSON array to a string
    `String` | `encodePrettily()` Encode the JSON array prettily as a string
    `boolean` | `equals(Object o)`
    `byte[]` | `getBinary(int pos)` Get the byte[] at position `pos` in the array.
    `Boolean` | `getBoolean(int pos)` Get the Boolean at position `pos` in the array,
    `Double` | `getDouble(int pos)` Get the Double at position `pos` in the array,
    `Float` | `getFloat(int pos)` Get the Float at position `pos` in the array,
    `Integer` | `getInteger(int pos)` Get the Integer at position `pos` in the array,
    `JsonArray` | `getJsonArray(int pos)` Get the JsonArray at position `pos` in the array.
    `JsonObject` | `getJsonObject(int pos)` Get the JsonObject at position `pos` in the array.
    `List` | `getList()` Get the unerlying List
    `Long` | `getLong(int pos)` Get the Long at position `pos` in the array,
    `String` | `getString(int pos)` Get the String at position `pos` in the array,
    `Object` | `getValue(int pos)` Get the Object value at position `pos` in the array.
    `int` | `hashCode()`
    `boolean` | `hasNull(int pos)` Is there a null value at position pos?
    `boolean` | `isEmpty()` Are there zero items in this JSON array?
    `Iterator<Object>` | `iterator()` Get an Iterator over the values in the JSON array
    `int` | `readFromBuffer(int pos, Buffer buffer)`
    `Object` | `remove(int pos)` Remove the value at the specified position in the JSON array.
    `boolean` | `remove(Object value)` Remove the specified value from the JSON array.
    `int` | `size()` Get the number of values in this JSON array
    `java.util.stream.Stream<Object>` | `stream()` Get a Stream over the entries in the JSON array
    `String` | `toString()`
    `void` | `writeToBuffer(Buffer buffer)`

    - ### Methods inherited from class java.lang.Object

      `clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

    - ### Methods inherited from interface java.lang.Iterable

      `forEach, spliterator`

- - ### Constructor Detail

    - #### JsonArray

          public JsonArray(String json)

      Create an instance from a String of JSON
      Parameters:
        `json` - the string of JSON

    - #### JsonArray

          public JsonArray()

      Create an empty instance

    - #### JsonArray

          public JsonArray(List list)

      Create an instance from a List. The List is not copied.
      Parameters:
        `list` -

  - ### Method Detail

    - #### getString

          public String getString(int pos)

      Get the String at position `pos` in the array,
      Parameters:
        `pos` - the position in the array
      Returns:
        the String, or null if a null value present
      Throws:
        `ClassCastException` - if the value cannot be converted to String

    - #### getInteger

          public Integer getInteger(int pos)

      Get the Integer at position `pos` in the array,
      Parameters:
        `pos` - the position in the array
      Returns:
        the Integer, or null if a null value present
      Throws:
        `ClassCastException` - if the value cannot be converted to Integer

    - #### getLong

          public Long getLong(int pos)

      Get the Long at position `pos` in the array,
      Parameters:
        `pos` - the position in the array
      Returns:
        the Long, or null if a null value present
      Throws:
        `ClassCastException` - if the value cannot be converted to Long

    - #### getDouble

          public Double getDouble(int pos)

      Get the Double at position `pos` in the array,
      Parameters:
        `pos` - the position in the array
      Returns:
        the Double, or null if a null value present
      Throws:
        `ClassCastException` - if the value cannot be converted to Double

    - #### getFloat

          public Float getFloat(int pos)

      Get the Float at position `pos` in the array,
      Parameters:
        `pos` - the position in the array
      Returns:
        the Float, or null if a null value present
      Throws:
        `ClassCastException` - if the value cannot be converted to Float

    - #### getBoolean

          public Boolean getBoolean(int pos)

      Get the Boolean at position `pos` in the array,
      Parameters:
        `pos` - the position in the array
      Returns:
        the Boolean, or null if a null value present
      Throws:
        `ClassCastException` - if the value cannot be converted to Integer

    - #### getJsonObject

          public JsonObject getJsonObject(int pos)

      Get the JsonObject at position `pos` in the array.
      Parameters:
        `pos` - the position in the array
      Returns:
        the Integer, or null if a null value present
      Throws:
        `ClassCastException` - if the value cannot be converted to JsonObject

    - #### getJsonArray

          public JsonArray getJsonArray(int pos)

      Get the JsonArray at position `pos` in the array.
      Parameters:
        `pos` - the position in the array
      Returns:
        the Integer, or null if a null value present
      Throws:
        `ClassCastException` - if the value cannot be converted to JsonArray

    - #### getBinary

          public byte[] getBinary(int pos)

      Get the byte[] at position `pos` in the array.

      JSON itself has no notion of a binary, so this method assumes there is a String value and it contains a Base64 encoded binary, which it decodes if found and returns.

      This method should be used in conjunction with `add(byte[])`

      Parameters:
        `pos` - the position in the array
      Returns:
        the byte[], or null if a null value present
      Throws:
        `ClassCastException` - if the value cannot be converted to String

    - #### getValue

          public Object getValue(int pos)

      Get the Object value at position `pos` in the array.
      Parameters:
        `pos` - the position in the array
      Returns:
        the Integer, or null if a null value present

    - #### hasNull

          public boolean hasNull(int pos)

      Is there a null value at position pos?
      Parameters:
        `pos` - the position in the array
      Returns:
        true if null value present, false otherwise

    - #### add

          public JsonArray add(Enum value)

      Add an enum to the JSON array.

      JSON has no concept of encoding Enums, so the Enum will be converted to a String using the `Enum.name` method and the value added as a String.

      Parameters:
        `value` - the value
      Returns:
        a reference to this, so the API can be used fluently

    - #### add

          public JsonArray add(CharSequence value)

      Add a CharSequence to the JSON array.
      Parameters:
        `value` - the value
      Returns:
        a reference to this, so the API can be used fluently

    - #### add

          public JsonArray add(String value)

      Add a String to the JSON array.
      Parameters:
        `value` - the value
      Returns:
        a reference to this, so the API can be used fluently

    - #### add

          public JsonArray add(Integer value)

      Add an Integer to the JSON array.
      Parameters:
        `value` - the value
      Returns:
        a reference to this, so the API can be used fluently

    - #### add

          public JsonArray add(Long value)

      Add a Long to the JSON array.
      Parameters:
        `value` - the value
      Returns:
        a reference to this, so the API can be used fluently

    - #### add

          public JsonArray add(Double value)

      Add a Double to the JSON array.
      Parameters:
        `value` - the value
      Returns:
        a reference to this, so the API can be used fluently

    - #### add

          public JsonArray add(Float value)

      Add a Float to the JSON array.
      Parameters:
        `value` - the value
      Returns:
        a reference to this, so the API can be used fluently

    - #### add

          public JsonArray add(Boolean value)

      Add a Boolean to the JSON array.
      Parameters:
        `value` - the value
      Returns:
        a reference to this, so the API can be used fluently

    - #### addNull

          public JsonArray addNull()

      Add a null value to the JSON array.
      Returns:
        a reference to this, so the API can be used fluently

    - #### add

          public JsonArray add(JsonObject value)

      Add a JSON object to the JSON array.
      Parameters:
        `value` - the value
      Returns:
        a reference to this, so the API can be used fluently

    - #### add

          public JsonArray add(JsonArray value)

      Add another JSON array to the JSON array.
      Parameters:
        `value` - the value
      Returns:
        a reference to this, so the API can be used fluently

    - #### add

          public JsonArray add(byte[] value)

      Add a binary value to the JSON array.

      JSON has no notion of binary so the binary will be base64 encoded to a String, and the String added.

      Parameters:
        `value` - the value
      Returns:
        a reference to this, so the API can be used fluently

    - #### add

          public JsonArray add(Object value)

      Add an Object to the JSON array.
      Parameters:
        `value` - the value
      Returns:
        a reference to this, so the API can be used fluently

    - #### addAll

          public JsonArray addAll(JsonArray array)

      Appends all of the elements in the specified array to the end of this JSON array.
      Parameters:
        `array` - the array
      Returns:
        a reference to this, so the API can be used fluently

    - #### contains

          public boolean contains(Object value)

      Does the JSON array contain the specified value? This method will scan the entire array until it finds a value or reaches the end.
      Parameters:
        `value` - the value
      Returns:
        true if it contains the value, false if not

    - #### remove

          public boolean remove(Object value)

      Remove the specified value from the JSON array. This method will scan the entire array until it finds a value or reaches the end.
      Parameters:
        `value` - the value to remove
      Returns:
        true if it removed it, false if not found

    - #### remove

          public Object remove(int pos)

      Remove the value at the specified position in the JSON array.
      Parameters:
        `pos` - the position to remove the value at
      Returns:
        the removed value if removed, null otherwise

    - #### size

          public int size()

      Get the number of values in this JSON array
      Returns:
        the number of items

    - #### isEmpty

          public boolean isEmpty()

      Are there zero items in this JSON array?
      Returns:
        true if zero, false otherwise

    - #### getList

          public List getList()

      Get the unerlying List
      Returns:
        the underlying List

    - #### clear

          public JsonArray clear()

      Remove all entries from the JSON array
      Returns:
        a reference to this, so the API can be used fluently

    - #### iterator

          public Iterator<Object> iterator()

      Get an Iterator over the values in the JSON array
      Specified by:
        `iterator` in interface `Iterable<Object>`
      Returns:
        an iterator

    - #### encode

          public String encode()

      Encode the JSON array to a string
      Returns:
        the string encoding

    - #### encodePrettily

          public String encodePrettily()

      Encode the JSON array prettily as a string
      Returns:
        the string encoding

    - #### copy

          public JsonArray copy()

      Make a copy of the JSON array
      Returns:
        a copy

    - #### stream

          public java.util.stream.Stream<Object> stream()

      Get a Stream over the entries in the JSON array
      Returns:
        a Stream

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Object`

    - #### equals

          public boolean equals(Object o)

      Overrides:
        `equals` in class `Object`

    - #### hashCode

          public int hashCode()

      Overrides:
        `hashCode` in class `Object`

    - #### writeToBuffer

          public void writeToBuffer(Buffer buffer)

      Specified by:
        `writeToBuffer` in interface `io.vertx.core.shareddata.impl.ClusterSerializable`

    - #### readFromBuffer

          public int readFromBuffer(int pos,
                                    Buffer buffer)

      Specified by:
        `readFromBuffer` in interface `io.vertx.core.shareddata.impl.ClusterSerializable`

Copyright © 2015. All Rights Reserved.