public class JsonArray extends JsonValue implements Iterable<Object>, Serializable
NullPointerException
s.
The JsonArray
is backed by a List
and is intended to work similar to it API wise, but to only
allow to store such objects which can be represented by JSON.Modifier and Type | Method and Description |
---|---|
JsonArray |
add(boolean value)
|
JsonArray |
add(double value)
|
JsonArray |
add(int value)
|
JsonArray |
add(JsonArray value)
|
JsonArray |
add(JsonObject value)
Append an
JsonObject element to the JsonArray . |
JsonArray |
add(List<?> value)
|
JsonArray |
add(long value)
|
JsonArray |
add(Map<String,?> value)
|
JsonArray |
add(Number value)
|
JsonArray |
add(Object value)
Append an element to the
JsonArray . |
JsonArray |
add(String value)
|
JsonArray |
addNull()
Append a null element to the
JsonArray . |
boolean |
contains(Object value)
Returns true if the object is part of the array.
|
static JsonArray |
create()
Creates a empty
JsonArray . |
static JsonArray |
create(int initialCapacity)
Creates a empty
JsonArray . |
boolean |
equals(Object o) |
static JsonArray |
from(List<?> items)
|
static JsonArray |
from(Object... items)
Creates a new
JsonArray and populates it with the values supplied. |
static JsonArray |
fromJson(byte[] s) |
static JsonArray |
fromJson(String s)
|
Object |
get(int index)
Retrieves the value by the position in the
JsonArray and does not cast it. |
JsonArray |
getArray(int index)
|
BigDecimal |
getBigDecimal(int index)
Retrieves the value by the position in the
JsonArray and casts it to BigDecimal . |
BigInteger |
getBigInteger(int index)
Retrieves the value by the position in the
JsonArray and casts it to BigInteger . |
boolean |
getBoolean(int index)
|
Double |
getDouble(int index)
|
Integer |
getInt(int index)
|
Long |
getLong(int index)
|
Number |
getNumber(int index)
|
JsonObject |
getObject(int index)
Retrieves the value by the position in the
JsonArray and casts it to JsonObject . |
String |
getString(int index)
|
int |
hashCode() |
boolean |
isEmpty()
Checks if the
JsonArray is empty or not. |
Iterator<Object> |
iterator() |
int |
size()
Returns the size of the
JsonArray . |
byte[] |
toBytes()
Similar to
toString() but turns this array directly into an encoded byte array. |
List<Object> |
toList()
|
String |
toString()
Converts the
JsonArray into its JSON string representation. |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
forEach, spliterator
public static JsonArray create(int initialCapacity)
JsonArray
.initialCapacity
- the initial capacity for this json array.JsonArray
.public static JsonArray from(Object... items)
JsonArray
and populates it with the values supplied.
If the type is not supported, a InvalidArgumentException
exception is thrown.public static JsonArray from(List<?> items)
JsonArray
containing items from the given List
,
in the same order they were returned by the list's iterator.
Sub Maps and Iterables:
If possible, contained Maps and Iterables are converted to JsonObject and
JsonArray respectively. However, some restrictions apply. Any non-convertible item
will raise a ClassCastException
. If the sub-conversion raises an exception (like an
InvalidArgumentException) then it is put as cause for the ClassCastException.
items
- the list of items to be stored in the JsonArray
.JsonArray
containing the elements from the given list,
in the order they were returned by the list's iterator.com.couchbase.client.core.error.InvalidArgumentException
- if one or more items is of unsupported type.NullPointerException
- if the given list is null.public static JsonArray fromJson(String s)
JsonArray
from a JSON String
.
Not to be confused with from(Object...)
from(aString)} which will populate a new array with the string.
The string is expected to be a valid JSON array representation (eg. starting with a '[').public static JsonArray fromJson(byte[] s)
public Object get(int index)
JsonArray
and does not cast it.index
- the index of the value.IndexOutOfBoundsException
- if the index is negative or too large.public JsonArray add(Object value)
JsonArray
.
Note that the type is checked and a InvalidArgumentException
is thrown if not supported.value
- the value to append.JsonArray
.public JsonArray addNull()
JsonArray
.
This is equivalent to calling add(Object)
with null or JsonValue.NULL
.JsonArray
.public JsonArray add(String value)
value
- the value to append.JsonArray
.public String getString(int index)
index
- the index of the value.IndexOutOfBoundsException
- if the index is negative or too large.public JsonArray add(long value)
value
- the value to append.JsonArray
.public Long getLong(int index)
JsonArray
and casts it to Long
.
Note that if value was stored as another numerical type, some truncation or rounding may occur.index
- the index of the value.IndexOutOfBoundsException
- if the index is negative or too large.public JsonArray add(int value)
value
- the value to append.JsonArray
.public Integer getInt(int index)
JsonArray
and casts it to Integer
.
Note that if value was stored as another numerical type, some truncation or rounding may occur.index
- the index of the value.IndexOutOfBoundsException
- if the index is negative or too large.public JsonArray add(double value)
value
- the value to append.JsonArray
.public Double getDouble(int index)
JsonArray
and casts it to Double
.
Note that if value was stored as another numerical type, some truncation or rounding may occur.index
- the index of the value.IndexOutOfBoundsException
- if the index is negative or too large.public JsonArray add(boolean value)
value
- the value to append.JsonArray
.public boolean getBoolean(int index)
index
- the index of the value.IndexOutOfBoundsException
- if the index is negative or too large.public JsonArray add(JsonObject value)
JsonObject
element to the JsonArray
.value
- the value to append.JsonArray
.public JsonArray add(Map<String,?> value)
value
- the value to append.JsonArray
.JsonObject.from(Map)
public JsonObject getObject(int index)
JsonArray
and casts it to JsonObject
.index
- the index of the value.IndexOutOfBoundsException
- if the index is negative or too large.public JsonArray add(JsonArray value)
value
- the value to append.JsonArray
.public JsonArray add(List<?> value)
value
- the value to append.JsonArray
.from(List)
public JsonArray add(Number value)
value
- the value to append.JsonArray
.public JsonArray getArray(int index)
index
- the index of the value.IndexOutOfBoundsException
- if the index is negative or too large.public BigInteger getBigInteger(int index)
JsonArray
and casts it to BigInteger
.index
- the index of the value.IndexOutOfBoundsException
- if the index is negative or too large.public BigDecimal getBigDecimal(int index)
JsonArray
and casts it to BigDecimal
.index
- the index of the value.IndexOutOfBoundsException
- if the index is negative or too large.public Number getNumber(int index)
index
- the index of the value.IndexOutOfBoundsException
- if the index is negative or too large.public boolean isEmpty()
JsonArray
is empty or not.public int size()
JsonArray
.public boolean contains(Object value)
value
- the value to check.public byte[] toBytes()
toString()
but turns this array directly into an encoded byte array.JsonArray
.Copyright © 2024 Couchbase, Inc.. All rights reserved.