public class JsonArray extends java.util.ArrayList<java.lang.Object> implements JsonType
JSON_ARRAY_END, JSON_ARRAY_START, JSON_ELEMENT_SEPARATOR, JSON_LITERAL_FALSE, JSON_LITERAL_NULL, JSON_LITERAL_TRUE, JSON_OBJECT_END, JSON_OBJECT_START, JSON_PAIR_SEPARATOR, JSON_STRING_DELIMITER, JSON_STRING_ESCAPE
Constructor and Description |
---|
JsonArray(java.util.Collection<? extends java.lang.Object> collection) |
JsonArray(int initialCapacity) |
JsonArray(java.lang.Object... objects) |
Modifier and Type | Method and Description |
---|---|
boolean |
add(java.lang.Object object)
Adds the given element if it is a valid JSON object type.
|
void |
addElements(java.lang.Object... elements)
Adds all given elements if they are valid JSON object types, which are:
JsonObject
JsonArray
String
Boolean
Integer
Long
BigDecimal
null
Objects of other types will cause an exception.
|
void |
appendAsJSONString(java.lang.Appendable output)
The receiver of this method must append its internal state as JSON string
representation to the given buffer.
|
<T> java.util.List<T> |
asList(java.lang.Class<T> elementType)
Returns a copy of this JsonArray as list of elements with the same type.
|
java.lang.String |
asString()
Returns the JSON string representation of this object.
|
java.math.BigDecimal |
getBigDecimal(int index)
Returns the value for the given index as BigDecimal (if it is one).
|
java.lang.Boolean |
getBoolean(int index)
Returns the value for the given index as Boolean (if it is one).
|
java.lang.Integer |
getInteger(int index)
Returns the value for the given index as Integer (if it is one).
|
JsonArray |
getJsonArray(int index)
Returns the value at the given index as JsonArray (if it is one).
|
JsonObject |
getJsonObject(int index)
Returns the value at the given index as JsonObject (if it is one).
|
java.lang.Long |
getLong(int index)
Returns the value for the given index as Long (if it is one).
|
java.lang.Number |
getNumber(int index)
Returns the value for the given index as Number (if it is one).
|
java.lang.String |
getString(int index)
Returns the value for the given index as String (if it is one).
|
protected <T> T |
getTypedElement(int index,
java.lang.Class<T> type) |
<T> T |
getValueOfType(int index,
java.lang.Class<T> type)
Returns the value for the given index as type of the given class.
|
boolean |
isArray()
Returns true because this is a JSON array representation (in Java).
|
boolean |
isObject()
Returns false because this is no JSON object representation (in Java).
|
java.lang.String |
toJSON()
The receiver of this method returns its internal state as JSON string
representation.
|
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, trimToSize
public JsonArray(java.lang.Object... objects)
public JsonArray(java.util.Collection<? extends java.lang.Object> collection)
public JsonArray(int initialCapacity)
public JsonObject getJsonObject(int index)
index
- The index of the object to look for.java.lang.ClassCastException
- If the object at the given index is no JsonObject.public JsonArray getJsonArray(int index)
index
- The index of the array to look for.java.lang.ClassCastException
- If the object at the given index is no JsonArray.public java.lang.String getString(int index)
index
- The index of the value to look for.java.lang.ClassCastException
- If the object at the given index is no String.public java.lang.Boolean getBoolean(int index)
index
- The index of the value to look for.java.lang.ClassCastException
- If the object at the given index is no Boolean.public java.lang.Number getNumber(int index)
index
- The index of the value to look for.java.lang.ClassCastException
- If the object at the given index is no Number.public java.lang.Integer getInteger(int index)
index
- The index of the value to look for.java.lang.ClassCastException
- If the object at the given index is no Integer.public java.lang.Long getLong(int index)
index
- The index of the value to look for.java.lang.ClassCastException
- If the object at the given index is no Long.public java.math.BigDecimal getBigDecimal(int index)
index
- The index of the value to look for.java.lang.ClassCastException
- If the object at the given index is no BigDecimal.public <T> T getValueOfType(int index, java.lang.Class<T> type)
index
- The index of the value to look for.java.lang.IllegalArgumentException
- If the specified type is no valid JSON type.java.lang.ClassCastException
- If the object at the given index is not of the specified type.public boolean isObject()
public boolean isArray()
public boolean add(java.lang.Object object)
Valid types are:
add
in interface java.util.Collection<java.lang.Object>
add
in interface java.util.List<java.lang.Object>
add
in class java.util.ArrayList<java.lang.Object>
java.lang.IllegalArgumentException
- If the given object is not of a valid JSON type.public void addElements(java.lang.Object... elements)
java.lang.IllegalArgumentException
- If a given element is not of a valid JSON type.public <T> java.util.List<T> asList(java.lang.Class<T> elementType)
elementType
- The type all elements must have (must not be null).java.lang.ClassCastException
- If any of the elements in this JsonArray is not of the specified type.public java.lang.String asString()
asString
in interface IStringRepresentation
public void appendAsJSONString(java.lang.Appendable output)
IJSONConvertible
appendAsJSONString
in interface IJSONConvertible
output
- The output target to which to append the JSON string (must not be null).public java.lang.String toJSON()
IJSONConvertible
toJSON
in interface IJSONConvertible
protected <T> T getTypedElement(int index, java.lang.Class<T> type)