Package jodd.json

Class JsonArray

  • All Implemented Interfaces:
    java.lang.Iterable<java.lang.Object>

    public class JsonArray
    extends java.lang.Object
    implements java.lang.Iterable<java.lang.Object>
    Representation of JSON array.
    See Also:
    JsonObject
    • Constructor Summary

      Constructors 
      Constructor Description
      JsonArray()
      Creates an empty instance.
      JsonArray​(java.util.List list)
      Creates an instance from a List.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      JsonArray add​(byte[] value)
      Adds a binary value to the JSON array.
      JsonArray add​(java.lang.Boolean value)
      Adds a boolean to the JSON array.
      JsonArray add​(java.lang.CharSequence value)
      Adds a CharSequence to the JSON array.
      JsonArray add​(java.lang.Double value)
      Adds a double to the JSON array.
      JsonArray add​(java.lang.Enum value)
      Adds an enum to the JSON array.
      JsonArray add​(java.lang.Float value)
      Adds a float to the JSON array.
      JsonArray add​(java.lang.Integer value)
      Adds an integer to the JSON array.
      JsonArray add​(java.lang.Long value)
      Adds a long to the JSON array.
      JsonArray add​(java.lang.Object value)
      Adds an object to the JSON array.
      JsonArray add​(java.lang.String value)
      Adds a string to the JSON array.
      JsonArray add​(JsonArray value)
      Adds another JSON array to the JSON array.
      JsonArray add​(JsonObject value)
      Adds a JSON object 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()
      Adds a null value to the JSON array.
      JsonArray clear()
      Removes all entries from the JSON array.
      boolean contains​(java.lang.Object value)
      Returns true if given value exist.
      boolean equals​(java.lang.Object o)  
      byte[] getBinary​(int pos)
      Returns the byte[] at position pos in the array.
      java.lang.Boolean getBoolean​(int pos)
      Returns the boolean at position pos in the array.
      java.lang.Double getDouble​(int pos)
      Returns the double at position pos in the array.
      java.lang.Float getFloat​(int pos)
      Returns the Float at position pos in the array.
      java.lang.Integer getInteger​(int pos)
      Returns the integer at position pos in the array.
      JsonArray getJsonArray​(int pos)
      Returns the JsonArray at position pos in the array.
      JsonObject getJsonObject​(int pos)
      Returns the JsonObject at position pos in the array.
      java.lang.Long getLong​(int pos)
      Returns the long at position pos in the array.
      java.lang.String getString​(int pos)
      Returns the string at position pos in the array.
      java.lang.Object getValue​(int pos)
      Returns the object value at position pos in the array.
      int hashCode()  
      boolean hasNull​(int pos)
      Returns true if there is a null value at given index.
      boolean isEmpty()
      Returns true if JSON array is empty.
      java.util.Iterator<java.lang.Object> iterator()
      Returns an iterator over the values in the JSON array.
      java.util.List<java.lang.Object> list()
      Returns the underlying list.
      java.lang.Object remove​(int pos)
      Removes the value at the specified position in the JSON array.
      boolean remove​(java.lang.Object value)
      Removes the specified value from the JSON array.
      int size()
      Returns the number of values in this JSON array.
      java.util.stream.Stream<java.lang.Object> stream()
      Returns a Stream over the entries in the JSON array
      java.lang.String toString()  
      • 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()
        Creates an empty instance.
      • JsonArray

        public JsonArray​(java.util.List list)
        Creates an instance from a List. The List is not copied.
    • Method Detail

      • getString

        public java.lang.String getString​(int pos)
        Returns the string at position pos in the array.
      • getInteger

        public java.lang.Integer getInteger​(int pos)
        Returns the integer at position pos in the array.
      • getLong

        public java.lang.Long getLong​(int pos)
        Returns the long at position pos in the array.
      • getDouble

        public java.lang.Double getDouble​(int pos)
        Returns the double at position pos in the array.
      • getFloat

        public java.lang.Float getFloat​(int pos)
        Returns the Float at position pos in the array.
      • getBoolean

        public java.lang.Boolean getBoolean​(int pos)
        Returns the boolean at position pos in the array.
      • getJsonObject

        public JsonObject getJsonObject​(int pos)
        Returns the JsonObject at position pos in the array.
      • getJsonArray

        public JsonArray getJsonArray​(int pos)
        Returns the JsonArray at position pos in the array.
      • getBinary

        public byte[] getBinary​(int pos)
        Returns 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.

      • getValue

        public java.lang.Object getValue​(int pos)
        Returns the object value at position pos in the array.
      • hasNull

        public boolean hasNull​(int pos)
        Returns true if there is a null value at given index.
      • add

        public JsonArray add​(java.lang.Enum value)
        Adds 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.

      • add

        public JsonArray add​(java.lang.CharSequence value)
        Adds a CharSequence to the JSON array.
      • add

        public JsonArray add​(java.lang.String value)
        Adds a string to the JSON array.
      • add

        public JsonArray add​(java.lang.Integer value)
        Adds an integer to the JSON array.
      • add

        public JsonArray add​(java.lang.Long value)
        Adds a long to the JSON array.
      • add

        public JsonArray add​(java.lang.Double value)
        Adds a double to the JSON array.
      • add

        public JsonArray add​(java.lang.Float value)
        Adds a float to the JSON array.
      • add

        public JsonArray add​(java.lang.Boolean value)
        Adds a boolean to the JSON array.
      • addNull

        public JsonArray addNull()
        Adds a null value to the JSON array.
      • add

        public JsonArray add​(JsonArray value)
        Adds another JSON array to the JSON array.
      • add

        public JsonArray add​(byte[] value)
        Adds 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.

      • add

        public JsonArray add​(java.lang.Object value)
        Adds an object to the JSON array.
      • addAll

        public JsonArray addAll​(JsonArray array)
        Appends all of the elements in the specified array to the end of this JSON array.
      • contains

        public boolean contains​(java.lang.Object value)
        Returns true if given value exist.
      • remove

        public boolean remove​(java.lang.Object value)
        Removes the specified value from the JSON array.
      • remove

        public java.lang.Object remove​(int pos)
        Removes the value at the specified position in the JSON array.
      • size

        public int size()
        Returns the number of values in this JSON array.
      • isEmpty

        public boolean isEmpty()
        Returns true if JSON array is empty.
      • list

        public java.util.List<java.lang.Object> list()
        Returns the underlying list.
      • clear

        public JsonArray clear()
        Removes all entries from the JSON array.
      • iterator

        public java.util.Iterator<java.lang.Object> iterator()
        Returns an iterator over the values in the JSON array.
        Specified by:
        iterator in interface java.lang.Iterable<java.lang.Object>
      • stream

        public java.util.stream.Stream<java.lang.Object> stream()
        Returns a Stream over the entries in the JSON array
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • equals

        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object