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.
|
<T extends Enum<T>> |
getEnum(int index)
A convenience method that assumes there is a String value at the given index representing a fully qualified name
in dot notation of an enum.
|
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 <T extends Enum<T>> T getEnum(int index) throws ClassNotFoundException
T - the Enum type the value at the index is expected to belong to.index - representing where the value is expected to be at.ClassNotFoundException - if the element was a String but the declaring enum type couldn't be determined
with it.ClassCastException - if the element at the index was not a String or if the fully qualified enum
name is of the wrong type.IllegalArgumentException - if an enum type was dynamically determined but it doesn't define an enum with
the dynamically determined name.IndexOutOfBoundsException - if the index is outside of the range of element indexes in the JsonArray.Enum.valueOf(Class, String)public 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.Apache Camel