Package com.api.json
Class JSONArray
- java.lang.Object
-
- java.util.AbstractCollection<E>
-
- java.util.AbstractList<E>
-
- java.util.ArrayList<Object>
-
- com.api.json.JSONArray
-
- All Implemented Interfaces:
JSONArtifact,Serializable,Cloneable,Iterable<Object>,Collection<Object>,List<Object>,RandomAccess
public class JSONArray extends ArrayList<Object> implements JSONArtifact
- See Also:
- Serialized Form
-
-
Field Summary
-
Fields inherited from class java.util.AbstractList
modCount
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(int index, Object element)booleanadd(Object element)booleanaddAll(int index, Collection<?> collection)booleanaddAll(Collection<?> collection)static JSONArrayparse(InputStream is)Parses the supplied input stream to derive aJSONArraystatic JSONArrayparse(Reader reader)Parses the supplied reader to derive aJSONArraystatic JSONArrayparse(String input)Parses the supplied String to derive aJSONArrayStringserialize()Convert this object into a String of JSON text.Stringserialize(boolean verbose)voidserialize(OutputStream os)Convert this object into a stream of JSON text.voidserialize(OutputStream os, boolean verbose)Convert this object into a stream of JSON text.voidserialize(Writer writer)Convert this object into a stream of JSON text.voidserialize(Writer writer, boolean verbose)Convert this object into a stream of JSON text, specifying verbosity.Objectset(int index, Object element)StringtoString()StringtoString(StringBuilder sb, int indent, int incr)Abstract method to help with recursive formatting of JSON into a String-
Methods inherited from class java.util.ArrayList
clear, clone, contains, ensureCapacity, equals, forEach, get, hashCode, indexOf, isEmpty, iterator, lastIndexOf, listIterator, listIterator, remove, remove, removeAll, removeIf, removeRange, replaceAll, retainAll, size, sort, spliterator, subList, toArray, toArray, trimToSize
-
Methods inherited from class java.util.AbstractCollection
containsAll
-
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.util.Collection
parallelStream, stream, toArray
-
Methods inherited from interface java.util.List
containsAll
-
-
-
-
Method Detail
-
parse
public static JSONArray parse(InputStream is) throws IOException
Parses the supplied input stream to derive aJSONArray- Parameters:
is- The input stream to be parsed- Returns:
JSONArrayassociated with the input stream.- Throws:
IOException- If a parsing error occurs.
-
parse
public static JSONArray parse(Reader reader) throws IOException
Parses the supplied reader to derive aJSONArray- Parameters:
reader- The Reader to be parsed- Returns:
JSONArrayassociated with the input reader.- Throws:
IOException- If a parsing error occurs.
-
parse
public static JSONArray parse(String input) throws IOException
Parses the supplied String to derive aJSONArray- Parameters:
input- The String to be parsed- Returns:
JSONArrayassociated with the input String.- Throws:
IOException- If a parsing error occurs.
-
add
public void add(int index, Object element)
-
add
public boolean add(Object element)
-
addAll
public boolean addAll(Collection<?> collection)
-
addAll
public boolean addAll(int index, Collection<?> collection)
-
serialize
public String serialize() throws IOException
Description copied from interface:JSONArtifactConvert this object into a String of JSON text.- Specified by:
serializein interfaceJSONArtifact- Returns:
- String containing the JSON formatted according to the verbose flag.
- Throws:
IOException- Thrown on IO errors during serialization.
-
serialize
public String serialize(boolean verbose) throws IOException
- Specified by:
serializein interfaceJSONArtifact- Parameters:
verbose- Whether or not to write the JSON text in a verbose format.- Returns:
- String containing the JSON formatted according to the verbose flag.
- Throws:
IOException- Thrown on IO errors during serialization.
-
serialize
public void serialize(OutputStream os) throws IOException
Description copied from interface:JSONArtifactConvert this object into a stream of JSON text. Same as calling serialize(os,false); Note that encoding is always written as UTF-8, as per JSON spec.- Specified by:
serializein interfaceJSONArtifact- 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
Description copied from interface:JSONArtifactConvert this object into a stream of JSON text. Same as calling serialize(writer,false); Note that encoding is always written as UTF-8, as per JSON spec.- Specified by:
serializein interfaceJSONArtifact- 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
Description copied from interface:JSONArtifactConvert this object into a stream of JSON text. Same as calling serialize(writer,false);- Specified by:
serializein interfaceJSONArtifact- 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
Description copied from interface:JSONArtifactConvert this object into a stream of JSON text, specifying verbosity.- Specified by:
serializein interfaceJSONArtifact- Parameters:
writer- The writer which to serialize the JSON text to.verbose- Whether or not to write the JSON text in a verbose format.- Throws:
IOException- Thrown on IO errors during serialization.
-
toString
public String toString()
- Overrides:
toStringin classAbstractCollection<Object>
-
toString
public String toString(StringBuilder sb, int indent, int incr)
Description copied from interface:JSONArtifactAbstract method to help with recursive formatting of JSON into a String- Specified by:
toStringin interfaceJSONArtifact- Parameters:
sb- Buffer to receive formatted JSON contentindent- The amount of indentation expected in the formatted output.incr- the amount of incremental spacing used for formatted output.- Returns:
- Formatted JSON output.
-
-