Class JSONArray

All Implemented Interfaces:
JSONArtifact, Serializable, Cloneable, Iterable, Collection, List, RandomAccess

public class JSONArray extends ArrayList implements JSONArtifact
Extension of ArrayList that only allows values which are JSON-able. See JSONObject for a list of valid values. Instances of this class are not thread-safe.
See Also:
  • Constructor Details

    • JSONArray

      public JSONArray()
      Create a new instance of this class.
    • JSONArray

      public JSONArray(int initialCapacity)
      Create a new instance of this class with the specified initial capacity.
  • Method Details

    • add

      public void add(int index, Object element)
      Specified by:
      add in interface List
      Overrides:
      add in class ArrayList
    • add

      public boolean add(Object element)
      Specified by:
      add in interface Collection
      Specified by:
      add in interface List
      Overrides:
      add in class ArrayList
    • addAll

      public boolean addAll(Collection collection)
      Specified by:
      addAll in interface Collection
      Specified by:
      addAll in interface List
      Overrides:
      addAll in class ArrayList
    • addAll

      public boolean addAll(int index, Collection collection)
      Specified by:
      addAll in interface List
      Overrides:
      addAll in class ArrayList
    • set

      public Object set(int index, Object element)
      Specified by:
      set in interface List
      Overrides:
      set in class ArrayList
    • parse

      public static JSONArray parse(InputStream is) throws IOException
      Convert a stream of JSONArray text into JSONArray form.
      Parameters:
      is - The inputStream from which to read the JSON. It will assume the input stream is in UTF-8 and read it as such.
      Returns:
      The contructed JSONArray Object.
      Throws:
      IOEXception - Thrown if an underlying IO error from the stream occurs, or if malformed JSON is read,
      IOException
    • parse

      public static JSONArray parse(Reader reader) throws IOException
      Convert a stream (in reader form) of JSONArray text into object form.
      Parameters:
      reader - The reader from which the JSONArray data is read.
      Returns:
      The contructed JSONArray Object.
      Throws:
      IOEXception - Thrown if an underlying IO error from the reader occurs, or if malformed JSON is read,
      IOException
    • parse

      public static JSONArray parse(String str) throws IOException
      Convert a String of JSONArray text into object form.
      Parameters:
      str - The JSONArray string to parse into a Java Object.
      Returns:
      The contructed JSONArray Object.
      Throws:
      IOEXception - Thrown if malformed JSON is read,
      IOException
    • serialize

      public void serialize(OutputStream os) throws IOException
      Convert this object into a stream of JSON text. Same as calling serialize(os,false);
      Specified by:
      serialize in interface JSONArtifact
      Parameters:
      os - The output stream to serialize data to.
      Throws:
      IOException - Thrown on IO errors during serialization.
    • serialize

      public void serialize(OutputStream os, boolean verbose) throws IOException
      Convert this object into a stream of JSON text. Same as calling serialize(writer,false);
      Specified by:
      serialize in interface JSONArtifact
      Parameters:
      os - The output stream to serialize data to.
      verbose - Whether or not to write the JSON text in a verbose format.
      Throws:
      IOException - Thrown on IO errors during serialization.
    • serialize

      public void serialize(Writer writer) throws IOException
      Convert this object into a stream of JSON text. Same as calling serialize(writer,false);
      Specified by:
      serialize in interface JSONArtifact
      Parameters:
      writer - The writer which to serialize the JSON text to.
      Throws:
      IOException - Thrown on IO errors during serialization.
    • serialize

      public void serialize(Writer writer, boolean verbose) throws IOException
      Convert this object into a stream of JSON text, specifying verbosity.
      Specified by:
      serialize in interface JSONArtifact
      Parameters:
      writer - The writer which to serialize the JSON text to.
      Throws:
      IOException - Thrown on IO errors during serialization.
    • serialize

      public String serialize(boolean verbose) throws IOException
      Convert this object into a String of JSON text, specifying verbosity.
      Specified by:
      serialize in interface JSONArtifact
      Parameters:
      verbose - Whether or not to serialize in compressed for formatted Strings.
      Throws:
      IOException - Thrown on IO errors during serialization.
    • serialize

      public String serialize() throws IOException
      Convert this object into a String of JSON text. Same as serialize(false);
      Specified by:
      serialize in interface JSONArtifact
      Throws:
      IOException - Thrown on IO errors during serialization.