public class JsonArray extends ArrayList<Object> implements Jsonable
Jsoner,
Serialized FormmodCount| Constructor and Description |
|---|
JsonArray()Instantiates an empty JsonArray. |
JsonArray(Collection<?> collection)Instantiate a new JsonArray using ArrayList's constructor of the same type. |
| Modifier and Type | Method and Description |
|---|---|
<T> void | asCollection(Collection<T> destination)A convenience method that assumes every element of the JsonArray is castable to T before adding it to a
collection of Ts. |
BigDecimal | getBigDecimal(int index)A convenience method that assumes there is a BigDecimal, Number, or String at the given index. |
Boolean | getBoolean(int index)A convenience method that assumes there is a Boolean or String value at the given index. |
Byte | getByte(int index)A convenience method that assumes there is a Number or String value at the given index. |
<T extends Collection<?>> | getCollection(int index)A convenience method that assumes there is a Collection value at the given index. |
Double | getDouble(int index)A convenience method that assumes there is a Number or String value at the given index. |
Float | getFloat(int index)A convenience method that assumes there is a Number or String value at the given index. |
Integer | getInteger(int index)A convenience method that assumes there is a Number or String value at the given index. |
Long | getLong(int index)A convenience method that assumes there is a Number or String value at the given index. |
<T extends Map<?,?>> | getMap(int index)A convenience method that assumes there is a Map value at the given index. |
Short | getShort(int index)A convenience method that assumes there is a Number or String value at the given index. |
String | getString(int index)A convenience method that assumes there is a Boolean, Number, or String value at the given index. |
String | toJson()Serialize to a JSON formatted string. |
void | toJson(Writer writable)Serialize to a JSON formatted stream. |
add, add, addAll, addAll, clear, clone, contains, ensureCapacity, forEach, get, indexOf, isEmpty, iterator, lastIndexOf, listIterator, listIterator, remove, remove, removeAll, removeIf, removeRange, replaceAll, retainAll, set, size, sort, spliterator, subList, toArray, toArray, trimToSizeequals, hashCodecontainsAll, toStringfinalize, getClass, notify, notifyAll, wait, wait, waitcontainsAll, equals, hashCodeparallelStream, streampublic JsonArray()
public JsonArray(Collection<?> collection)
collection - represents the elements to produce the JsonArray with.public <T> void asCollection(Collection<T> destination)
T - represents the type that all of the elements of the JsonArray should be cast to and the type the
collection will contain.destination - represents where all of the elements of the JsonArray are added to after being cast to the
generic type
provided.ClassCastException - if the unchecked cast of an element to T fails.public BigDecimal getBigDecimal(int index)
index - representing where the value is expected to be at.ClassCastException - if there was a value but didn't match the assumed return types.IndexOutOfBoundsException - if the index is outside of the range of element indexes in the JsonArray.NumberFormatException - if a String isn't a valid representation of a BigDecimal.BigDecimal,
Number.doubleValue()public Boolean getBoolean(int index)
index - represents where the value is expected to be at.ClassCastException - if there was a value but didn't match the assumed return type.IndexOutOfBoundsException - if the index is outside of the range of element indexes in the JsonArray.public Byte getByte(int index)
index - represents where the value is expected to be at.ClassCastException - if there was a value but didn't match the assumed return type.NumberFormatException - if a String isn't a valid representation of a BigDecimal or if the Number
represents the double or float Infinity or NaN.IndexOutOfBoundsException - if the index is outside of the range of element indexes in the JsonArray.Numberpublic <T extends Collection<?>> T getCollection(int index)
T - the kind of collection to expect at the index. Note unless manually added, collection values will be a
JsonArray.index - represents where the value is expected to be at.ClassCastException - if there was a value but didn't match the assumed return type.IndexOutOfBoundsException - if the index is outside of the range of element indexes in the JsonArray.Collectionpublic Double getDouble(int index)
index - represents where the value is expected to be at.ClassCastException - if there was a value but didn't match the assumed return type.NumberFormatException - if a String isn't a valid representation of a BigDecimal or if the Number
represents the double or float Infinity or NaN.IndexOutOfBoundsException - if the index is outside of the range of element indexes in the JsonArray.Numberpublic Float getFloat(int index)
index - represents where the value is expected to be at.ClassCastException - if there was a value but didn't match the assumed return type.NumberFormatException - if a String isn't a valid representation of a BigDecimal or if the Number
represents the double or float Infinity or NaN.IndexOutOfBoundsException - if the index is outside of the range of element indexes in the JsonArray.Numberpublic Integer getInteger(int index)
index - represents where the value is expected to be at.ClassCastException - if there was a value but didn't match the assumed return type.NumberFormatException - if a String isn't a valid representation of a BigDecimal or if the Number
represents the double or float Infinity or NaN.IndexOutOfBoundsException - if the index is outside of the range of element indexes in the JsonArray.Numberpublic Long getLong(int index)
index - represents where the value is expected to be at.ClassCastException - if there was a value but didn't match the assumed return type.NumberFormatException - if a String isn't a valid representation of a BigDecimal or if the Number
represents the double or float Infinity or NaN.IndexOutOfBoundsException - if the index is outside of the range of element indexes in the JsonArray.Numberpublic <T extends Map<?,?>> T getMap(int index)
T - the kind of map to expect at the index. Note unless manually added, Map values will be a JsonObject.index - represents where the value is expected to be at.ClassCastException - if there was a value but didn't match the assumed return type.IndexOutOfBoundsException - if the index is outside of the range of element indexes in the JsonArray.Mappublic Short getShort(int index)
index - represents where the value is expected to be at.ClassCastException - if there was a value but didn't match the assumed return type.NumberFormatException - if a String isn't a valid representation of a BigDecimal or if the Number
represents the double or float Infinity or NaN.IndexOutOfBoundsException - if the index is outside of the range of element indexes in the JsonArray.Numberpublic String getString(int index)
index - represents where the value is expected to be at.ClassCastException - if there was a value but didn't match the assumed return type.IndexOutOfBoundsException - if the index is outside of the range of element indexes in the JsonArray.public String toJson()
Jsonablepublic void toJson(Writer writable) throws IOException
JsonabletoJson in interface Jsonablewritable - where the resulting JSON text should be sent.IOException - when the writable encounters an I/O error.