public.javadoc.org.spincast.core.json.JsonArray.html Maven / Gradle / Ivy
Show all versions of spincast-website Show documentation
JsonArray (org.spincast:spincast-framework 1.0.0 API)
org.spincast.core.json
Interface JsonArray
-
- All Superinterfaces:
- Iterable<Object>, JsonObjectOrArray
- All Known Subinterfaces:
- SpincastXmlManager.JsonArrayMixIn
- All Known Implementing Classes:
- JsonArrayDefault
public interface JsonArray
extends JsonObjectOrArray, Iterable<Object>
Represents a Json
array, "[]".
-
-
Method Summary
All Methods Instance Methods Abstract Methods
Modifier and Type
Method and Description
JsonArray
add(int index,
Object value)
Inserts an object at the specified index in the array.
JsonArray
add(int index,
Object value,
boolean clone)
Adds an object at the specified index.
JsonArray
add(Object value)
Adds an object at the end of the array.
JsonArray
add(Object value,
boolean clone)
Adds an object at the end of the array.
JsonArray
addAll(Collection<?> values)
Adds all elements at the end of the array.
JsonArray
addAll(Collection<?> values,
boolean clone)
Adds all elements at the end of the array.
JsonArray
addAll(JsonArray values)
Adds all elements at the end of the array.
JsonArray
addAll(JsonArray values,
boolean clone)
Adds elements at the end of the array.
JsonArray
addAll(Object[] values)
Adds all elements at the end of the array.
JsonArray
addAll(Object[] values,
boolean clone)
Adds elements at the end of the array.
JsonArray
clone(boolean mutable)
Deep copy of the JsonArray
, so any
modification to the original won't affect the
clone, and vice-versa.
List<Object>
convertToPlainList()
Converts the JsonArray
to a plain List<Object>
.
List<String>
convertToStringList()
Converts the JsonArray to a List<String>
.
BigDecimal
getArrayFirstBigDecimal(int index)
Gets the first element (as BigDecimal) of a JsonArray
element.
BigDecimal
getArrayFirstBigDecimal(int index,
BigDecimal defaultValue)
Gets the first element (as BigDecimal) of a JsonArray
element.
Boolean
getArrayFirstBoolean(int index)
Gets the first element (as Boolean) of a JsonArray
element.
Boolean
getArrayFirstBoolean(int index,
Boolean defaultValue)
Gets the first element (as Boolean) of a JsonArray
element.
byte[]
getArrayFirstBytesFromBase64String(int index)
Gets the first element (as byte[]) of a JsonArray
element.
byte[]
getArrayFirstBytesFromBase64String(int index,
byte[] defaultValue)
Gets the first element (as byte[]) of a JsonArray
element.
Date
getArrayFirstDate(int index)
Gets the first element (as Date) of a JsonArray
element.
Date
getArrayFirstDate(int index,
Date defaultValue)
Gets the first element (as Date) of a JsonArray
element.
Double
getArrayFirstDouble(int index)
Gets the first element (as Double) of a JsonArray
element.
Double
getArrayFirstDouble(int index,
Double defaultValue)
Gets the first element (as Double) of a JsonArray
element.
Float
getArrayFirstFloat(int index)
Gets the first element (as Float) of a JsonArray
element.
Float
getArrayFirstFloat(int index,
Float defaultValue)
Gets the first element (as Float) of a JsonArray
element.
Instant
getArrayFirstInstant(int index)
Gets the first element (as Instant) of a JsonArray
element.
Instant
getArrayFirstInstant(int index,
Instant defaultValue)
Gets the first element (as Instant) of a JsonArray
element.
Integer
getArrayFirstInteger(int index)
Gets the first element (as Integer) of a JsonArray
element.
Integer
getArrayFirstInteger(int index,
Integer defaultValue)
Gets the first element (as Integer) of a JsonArray
element.
JsonArray
getArrayFirstJsonArray(int index)
Gets the first element (as JsonArray) of a JsonArray
element.
JsonArray
getArrayFirstJsonArray(int index,
JsonArray defaultValue)
Gets the first element (as JsonArray) of a JsonArray
element.
JsonObject
getArrayFirstJsonObject(int index)
Gets the first element (as JsonObject) of a JsonArray
element.
JsonObject
getArrayFirstJsonObject(int index,
JsonObject defaultValue)
Gets the first element (as JsonObject) of a JsonArray
element.
Long
getArrayFirstLong(int index)
Gets the first element (as Long) of a JsonArray
element.
Long
getArrayFirstLong(int index,
Long defaultValue)
Gets the first element (as Long) of a JsonArray
element.
String
getArrayFirstString(int index)
Gets the first element (as String) of a JsonArray
element.
String
getArrayFirstString(int index,
String defaultValue)
Gets the first element (as String) of a JsonArray
element.
BigDecimal
getBigDecimal(int index)
Gets an element as BigDecimal
.
BigDecimal
getBigDecimal(int index,
BigDecimal defaultValue)
Gets an element as BigDecimal
.
Boolean
getBoolean(int index)
Gets an element as Boolean
.
Boolean
getBoolean(int index,
Boolean defaultValue)
Gets an element as Boolean
.
byte[]
getBytesFromBase64String(int index)
Gets a byte array, from a base 64 encoded element.
byte[]
getBytesFromBase64String(int index,
byte[] defaultValue)
Gets a byte array, from a base 64 encoded element.
Date
getDate(int index)
Gets a UTC timezoned date from a ISO 8601
date element.
Date
getDate(int index,
Date defaultValue)
Gets a UTC timezoned date from a ISO 8601
date element.
Double
getDouble(int index)
Gets an element as Double
.
Double
getDouble(int index,
Double defaultValue)
Gets an element as Double
.
Float
getFloat(int index)
Gets an element as Float
.
Float
getFloat(int index,
Float defaultValue)
Gets an element as Float
.
Instant
getInstant(int index)
Gets an Instant from a ISO 8601
date element.
Instant
getInstant(int index,
Instant defaultValue)
Gets an Instant from a ISO 8601
date element.
Integer
getInteger(int index)
Gets an element as Integer
.
Integer
getInteger(int index,
Integer defaultValue)
Gets an element as Integer
.
JsonArray
getJsonArray(int index)
Gets an element as JsonArray
.
JsonArray
getJsonArray(int index,
JsonArray defaultValue)
Gets an element as JsonArray
.
JsonArray
getJsonArrayOrEmpty(int index)
Gets an element as JsonArray
.
JsonObject
getJsonObject(int index)
Gets an element as JsonObject
.
JsonObject
getJsonObject(int index,
JsonObject defaultValue)
Gets an element as JsonObject
.
JsonObject
getJsonObjectOrEmpty(int index)
Gets an element as JsonObject
.
Long
getLong(int index)
Gets an element as Long
.
Long
getLong(int index,
Long defaultValue)
Gets an element as Long
.
Object
getObject(int index)
Gets an element, untyped.
Object
getObject(int index,
Object defaultValue)
Gets an element, untyped.
String
getString(int index)
Gets an element as String
.
String
getString(int index,
String defaultValue)
Gets an element as String
.
boolean
isCanBeConvertedToBigDecimal(int index)
Validates that the element at the specified index
exists and
is currently null
, of type BigDecimal
, or can be
converted and retrieved as one.
boolean
isCanBeConvertedToBoolean(int index)
Validates that the element at the specified index
exists and
is currently null
, of type Boolean
, or can be
converted and retrieved as one.
boolean
isCanBeConvertedToByteArray(int index)
Validates that the element at the specified index
exists and
is currently null
, of type base 64 String
representing
a byte array, or can be converted and retrieved as one.
boolean
isCanBeConvertedToDate(int index)
Validates that the element at the specified index
exists and
is currently null
, of type Date
, or can be
converted and retrieved as one.
boolean
isCanBeConvertedToDouble(int index)
Validates that the element at the specified index
exists and
is currently null
, of type Double
, or can be
converted and retrieved as one.
boolean
isCanBeConvertedToFloat(int index)
Validates that the element at the specified index
exists and
is currently null
, of type Float
, or can be
converted and retrieved as one.
boolean
isCanBeConvertedToInteger(int index)
Validates that the element at the specified index
exists and
is currently null
, of type Integer
, or can be
converted and retrieved as one.
boolean
isCanBeConvertedToJsonArray(int index)
Validates that the element at the specified index
exists and
is currently null
, of type JsonArray
, or can be
converted and retrieved as one.
boolean
isCanBeConvertedToJsonObject(int index)
Validates that the element at the specified index
exists and
is currently null
, of type JsonObject
, or can be
converted and retrieved as one.
boolean
isCanBeConvertedToLong(int index)
Validates that the element at the specified index
exists and
is currently null
, of type Long
, or can be
converted and retrieved as one.
boolean
isCanBeConvertedToString(int index)
Validates that the element at the specified index
exists and
is currently null
, of type String
, or can be
converted and retrieved as one.
boolean
isElementExists(int index)
Is there an element at the specified index? This returns
true
even if the element is null
.
boolean
isEquivalentTo(JsonArray other)
Compares the current JsonArray
to the specified one
and returns true
if they are equivalent.
boolean
isNull(int index)
Validates that there is an element at the specified index
and
it is null
.
boolean
isOfTypeBigDecimal(int index)
Validates that the element at the specified index
exists and
is currently null
or of type BigDecimal
, without requiring
any conversion.
boolean
isOfTypeBoolean(int index)
Validates that the element at the specified index
exists and
is currently null
or of type Boolean
, without requiring
any conversion.
boolean
isOfTypeByteArray(int index,
boolean acceptBase64StringToo)
Validates that the element at the specified JsonPath
exists and
is currently null
or of type byte[]
, without requiring
any conversion.
boolean
isOfTypeDate(int index)
Validates that the element at the specified index
exists and
is currently null
or of type Date
, without requiring
any conversion.
boolean
isOfTypeDouble(int index)
Validates that the element at the specified index
exists and
is currently null
or of type Double
, without requiring
any conversion.
boolean
isOfTypeFloat(int index)
Validates that the element at the specified index
exists and
is currently null
or of type Float
, without requiring
any conversion.
boolean
isOfTypeInteger(int index)
Validates that the element at the specified index
exists and
is currently null
or of type Integer
, without requiring
any conversion.
boolean
isOfTypeJsonArray(int index)
Validates that the element at the specified index
exists and
is currently null
or of type JsonArray
, without requiring
any conversion.
boolean
isOfTypeJsonObject(int index)
Validates that the element at the specified index
exists and
is currently null
or of type JsonObject
, without requiring
any conversion.
boolean
isOfTypeLong(int index)
Validates that the element at the specified index
exists and
is currently null
or of type Long
, without requiring
any conversion.
boolean
isOfTypeString(int index)
Validates that the element at the specified index
exists and
is currently null
or of type String
, without requiring
any conversion.
JsonArray
remove(int index)
Removes an element at the specified index.
JsonArray
set(int index,
Object value)
Sets an object at the specified index.
JsonArray
set(int index,
Object value,
boolean clone)
Sets an object at the specified index.
void
transform(int index,
ElementTransformer transformer)
Transforms the element at the given index, using the
specified ElementTransformer
.
void
trim(int index)
Trims the element, if it's of type String
.
-
Methods inherited from interface org.spincast.core.json.JsonObjectOrArray
clear, contains, getArrayFirstBigDecimal, getArrayFirstBigDecimal, getArrayFirstBoolean, getArrayFirstBoolean, getArrayFirstBytesFromBase64String, getArrayFirstBytesFromBase64String, getArrayFirstDate, getArrayFirstDate, getArrayFirstDouble, getArrayFirstDouble, getArrayFirstFloat, getArrayFirstFloat, getArrayFirstInstant, getArrayFirstInstant, getArrayFirstInteger, getArrayFirstInteger, getArrayFirstJsonArray, getArrayFirstJsonArray, getArrayFirstJsonObject, getArrayFirstJsonObject, getArrayFirstLong, getArrayFirstLong, getArrayFirstString, getArrayFirstString, getBigDecimal, getBigDecimal, getBoolean, getBoolean, getBytesFromBase64String, getBytesFromBase64String, getDate, getDate, getDouble, getDouble, getFloat, getFloat, getInstant, getInstant, getInteger, getInteger, getJsonArray, getJsonArray, getJsonArrayOrEmpty, getJsonArrayOrEmpty, getJsonObject, getJsonObject, getJsonObjectOrEmpty, getJsonObjectOrEmpty, getLong, getLong, getObject, getObject, getString, getString, isCanBeConvertedToBigDecimal, isCanBeConvertedToBoolean, isCanBeConvertedToByteArray, isCanBeConvertedToDate, isCanBeConvertedToDouble, isCanBeConvertedToFloat, isCanBeConvertedToInteger, isCanBeConvertedToJsonArray, isCanBeConvertedToJsonObject, isCanBeConvertedToLong, isCanBeConvertedToString, isMutable, isNull, isOfTypeBigDecimal, isOfTypeBoolean, isOfTypeByteArray, isOfTypeDate, isOfTypeDouble, isOfTypeFloat, isOfTypeInteger, isOfTypeJsonArray, isOfTypeJsonObject, isOfTypeLong, isOfTypeString, remove, set, set, size, toJsonString, toJsonString, transform, transformAll, transformAll, trim, trimAll, trimAll
-
Methods inherited from interface java.lang.Iterable
forEach, iterator, spliterator
-
-
Method Detail
-
add
JsonArray add(Object value)
Adds an object at the end of the array.
If the object to add is not of a native type,
then the object is converted before being added.
Once the object is converted and added, a modification of the original
object won't affect this element, and vice-versa.
If the element to add is a JsonObject
or
a JsonArray
and is immutable, it will be cloned.
Doing so, we can make sure the JsonArray
is always
fully mutable or fully immutable.
If the element implements ToJsonObjectConvertible
, it
will be converted to a JsonObject
using the associated
conversion method. If it implements ToJsonArrayConvertible
, it
will be converted to an JsonArray
using the associated
conversion method.
Those are the types of objects that will be converted to a
JsonArray
instead of a JsonObject
, if
no conversion interface is implemented :
-
A Collection
-
An array
-
add
JsonArray add(int index,
Object value)
Inserts an object at the specified index in the array.
Any existing elements starting at this index are
pushed to the right.
If the specified index is greater than the current
end of the array, null
elements are
added to fill up positionss up to the specified index!
Use set
instead if you want
to replace the element at the specified index.
If the object to add is not of a native type,
then the object is converted before being added.
Once the object is converted and added, a modification of the original
object won't affect this element, and vice-versa.
If the element to add is a JsonObject
or
a JsonArray
and is immutable, it will be cloned.
Doing so, we can make sure the JsonArray
is always
fully mutable or fully immutable.
If the element implements ToJsonObjectConvertible
, it
will be converted to a JsonObject
using the associated
conversion method. If it implements ToJsonArrayConvertible
, it
will be converted to an JsonArray
using the associated
conversion method.
Those are the types of objects that will be converted to a
JsonArray
instead of a JsonObject
, if
no conversion interface is implemented :
-
A Collection
-
An array
-
add
JsonArray add(Object value,
boolean clone)
Adds an object at the end of the array.
If the object to add is not of a native type,
then the object is converted before being added.
Once the object is converted and added, a modification of the original
object won't affect this element, and vice-versa.
If the element to add is a JsonObject
or
a JsonArray
and is immutable, it will be cloned.
Doing so, we can make sure the JsonArray
is always
fully mutable or fully immutable.
If the element implements ToJsonObjectConvertible
, it
will be converted to a JsonObject
using the associated
conversion method. If it implements ToJsonArrayConvertible
, it
will be converted to an JsonArray
using the associated
conversion method.
Those are the types of objects that will be converted to a
JsonArray
instead of a JsonObject
, if
no conversion interface is implemented :
-
A Collection
-
An array
- Parameters:
clone
- if true
, and the element to add is a
JsonObject
or JsonArray
, a clone will be made
before being added. If that case, any modification to the
original element won't affect the added one,
and vice-versa. If the element is immutable then it will
always be cloned. Doing so, we can make sure a
JsonArray
is always
fully mutable or fully immutable.
-
add
JsonArray add(int index,
Object value,
boolean clone)
Adds an object at the specified index.
Any existing elements starting at this index are
pushed to the right.
If the specified index is greater than the current
end of the array, null
elements are
added to fill positions up to the specified index!
Use set
instead if you want
to replace the element at the specified index.
If the object to add is not of a native type,
then the object is converted before being added.
Once the object is converted and added, a modification of the original
object won't affect this element, and vice-versa.
If the element to add is a JsonObject
or
a JsonArray
and is immutable, it will be cloned.
Doing so, we can make sure the JsonArray
is always
fully mutable or fully immutable.
If the element implements ToJsonObjectConvertible
, it
will be converted to a JsonObject
using the associated
conversion method. If it implements ToJsonArrayConvertible
, it
will be converted to an JsonArray
using the associated
conversion method.
Those are the types of objects that will be converted to a
JsonArray
instead of a JsonObject
, if
no conversion interface is implemented :
-
A Collection
-
An array
- Parameters:
clone
- if true
, and the element to add is a
JsonObject
or JsonArray
, a clone will be made
before being added. If that case, any modification to the
original element won't affect the added one,
and vice-versa. If the element is immutable then it will
always be cloned. Doing so, we can make sure a
JsonArray
is always
fully mutable or fully immutable.
-
addAll
JsonArray addAll(Collection<?> values)
Adds all elements at the end of the array.
If an element to add is not of a native type,
then the element is converted before being added.
Once the element is converted and added, a modification of the original
object won't affect this element, and vice-versa.
If an element to add is a JsonObject
or
a JsonArray
and is immutable, it will be cloned.
Doing so, we can make sure the JsonArray
is always
fully mutable or fully immutable.
If the element implements ToJsonObjectConvertible
, it
will be converted to a JsonObject
using the associated
conversion method. If it implements ToJsonArrayConvertible
, it
will be converted to an JsonArray
using the associated
conversion method.
Those are the types of objects that will be converted to a
JsonArray
instead of a JsonObject
, if
no conversion interface is implemented :
-
A Collection
-
An array
-
addAll
JsonArray addAll(Collection<?> values,
boolean clone)
Adds all elements at the end of the array.
If an element to add is not of a native type,
then the element is converted before being added.
Once the element is converted and added, a modification of the original
object won't affect this element, and vice-versa.
If an element to add is a JsonObject
or
a JsonArray
and is immutable, it will be cloned.
Doing so, we can make sure the JsonArray
is always
fully mutable or fully immutable.
If the element implements ToJsonObjectConvertible
, it
will be converted to a JsonObject
using the associated
conversion method. If it implements ToJsonArrayConvertible
, it
will be converted to an JsonArray
using the associated
conversion method.
Those are the types of objects that will be converted to a
JsonArray
instead of a JsonObject
, if
no conversion interface is implemented :
-
A Collection
-
An array
- Parameters:
clone
- if true
, and the element to add is a
JsonObject
or JsonArray
, a clone will be made
before being added. If that case, any modification to the
original element won't affect the added one,
and vice-versa. If the element is immutable then it will
always be cloned. Doing so, we can make sure a
JsonArray
is always
fully mutable or fully immutable.
-
addAll
JsonArray addAll(Object[] values)
Adds all elements at the end of the array.
If an element to add is not of a native type,
then the element is converted before being added.
Once the element is converted and added, a modification of the original
object won't affect this element, and vice-versa.
If an element to add is a JsonObject
or
a JsonArray
and is immutable, it will be cloned.
Doing so, we can make sure the JsonArray
is always
fully mutable or fully immutable.
If the element implements ToJsonObjectConvertible
, it
will be converted to a JsonObject
using the associated
conversion method. If it implements ToJsonArrayConvertible
, it
will be converted to an JsonArray
using the associated
conversion method.
Those are the types of objects that will be converted to a
JsonArray
instead of a JsonObject
, if
no conversion interface is implemented :
-
A Collection
-
An array
-
addAll
JsonArray addAll(Object[] values,
boolean clone)
Adds elements at the end of the array.
If an element to add is not of a native type,
then the element is converted before being added.
Once the element is converted and added, a modification of the original
object won't affect this element, and vice-versa.
If an element to add is a JsonObject
or
a JsonArray
and is immutable, it will be cloned.
Doing so, we can make sure the JsonArray
is always
fully mutable or fully immutable.
If the element implements ToJsonObjectConvertible
, it
will be converted to a JsonObject
using the associated
conversion method. If it implements ToJsonArrayConvertible
, it
will be converted to an JsonArray
using the associated
conversion method.
Those are the types of objects that will be converted to a
JsonArray
instead of a JsonObject
, if
no conversion interface is implemented :
-
A Collection
-
An array
- Parameters:
clone
- if true
, and the element to add is a
JsonObject
or JsonArray
, a clone will be made
before being added. If that case, any modification to the
original element won't affect the added one,
and vice-versa. If the element is immutable then it will
always be cloned. Doing so, we can make sure a
JsonArray
is always
fully mutable or fully immutable.
-
addAll
JsonArray addAll(JsonArray values)
Adds all elements at the end of the array.
If an element to add is not of a native type,
then the element is converted before being added.
Once the element is converted and added, a modification of the original
object won't affect this element, and vice-versa.
If an element to add is a JsonObject
or
a JsonArray
and is immutable, it will be cloned.
Doing so, we can make sure the JsonArray
is always
fully mutable or fully immutable.
If the element implements ToJsonObjectConvertible
, it
will be converted to a JsonObject
using the associated
conversion method. If it implements ToJsonArrayConvertible
, it
will be converted to an JsonArray
using the associated
conversion method.
Those are the types of objects that will be converted to a
JsonArray
instead of a JsonObject
, if
no conversion interface is implemented :
-
A Collection
-
An array
-
addAll
JsonArray addAll(JsonArray values,
boolean clone)
Adds elements at the end of the array.
If an element to add is not of a native type,
then the element is converted before being added.
Once the element is converted and added, a modification of the original
object won't affect this element, and vice-versa.
If an element to add is a JsonObject
or
a JsonArray
and is immutable, it will be cloned.
Doing so, we can make sure the JsonArray
is always
fully mutable or fully immutable.
If the element implements ToJsonObjectConvertible
, it
will be converted to a JsonObject
using the associated
conversion method. If it implements ToJsonArrayConvertible
, it
will be converted to an JsonArray
using the associated
conversion method.
Those are the types of objects that will be converted to a
JsonArray
instead of a JsonObject
, if
no conversion interface is implemented :
-
A Collection
-
An array
- Parameters:
clone
- if true
, and the element to add is a
JsonObject
or JsonArray
, a clone will be made
before being added. If that case, any modification to the
original element won't affect the added one,
and vice-versa. If the element is immutable then it will
always be cloned. Doing so, we can make sure a
JsonArray
is always
fully mutable or fully immutable.
-
set
JsonArray set(int index,
Object value)
Sets an object at the specified index.
If there is an element at this index, it is
overwritten.
If the specified index is greater than the current
end of the array, null
elements are
added to fill positions up to the specified index.
Use add
instead if you want
to insert the element at the specified index without
overwritting any existing element.
If an element to add is not of a native type,
then the element is converted before being added.
Once the element is converted and added, a modification of the original
object won't affect this element, and vice-versa.
If an element to add is a JsonObject
or
a JsonArray
and is immutable, it will be cloned.
Doing so, we can make sure the JsonArray
is always
fully mutable or fully immutable.
If the element implements ToJsonObjectConvertible
, it
will be converted to a JsonObject
using the associated
conversion method. If it implements ToJsonArrayConvertible
, it
will be converted to an JsonArray
using the associated
conversion method.
Those are the types of objects that will be converted to a
JsonArray
instead of a JsonObject
, if
no conversion interface is implemented :
-
A Collection
-
An array
-
set
JsonArray set(int index,
Object value,
boolean clone)
Sets an object at the specified index.
If there is an element at this index, it is
overwritten.
If the specified index is greater than the current
end of the array, null
elements are
added to fill positions up to the specified index.
Use add
instead if you want
to insert the element at the specified index without
overwritting any existing element.
If an element to add is not of a native type,
then the element is converted before being added.
Once the element is converted and added, a modification of the original
object won't affect this element, and vice-versa.
If an element to add is a JsonObject
or
a JsonArray
and is immutable, it will be cloned.
Doing so, we can make sure the JsonArray
is always
fully mutable or fully immutable.
If the element implements ToJsonObjectConvertible
, it
will be converted to a JsonObject
using the associated
conversion method. If it implements ToJsonArrayConvertible
, it
will be converted to an JsonArray
using the associated
conversion method.
Those are the types of objects that will be converted to a
JsonArray
instead of a JsonObject
, if
no conversion interface is implemented :
-
A Collection
-
An array
- Parameters:
clone
- if true
, and the element to add is a
JsonObject
or JsonArray
, a clone will be made
before being added. If that case, any modification to the
original element won't affect the added one,
and vice-versa. If the element is immutable then it will
always be cloned. Doing so, we can make sure a
JsonArray
is always
fully mutable or fully immutable.
-
remove
JsonArray remove(int index)
Removes an element at the specified index.
Any elements to the right are shift to the left.
If the index is invalid, nothing is done.
-
isElementExists
boolean isElementExists(int index)
Is there an element at the specified index? This returns
true
even if the element is null
.
This is a synonym of index >= 0 && index < size()
-
getJsonObject
JsonObject getJsonObject(int index)
throws CantConvertException
Gets an element as JsonObject
.
- Returns:
- the element or
null
if not found.
- Throws:
CantConvertException
- if an existing element can't be converted to the
required type.
-
getJsonObject
JsonObject getJsonObject(int index,
JsonObject defaultValue)
throws CantConvertException
Gets an element as JsonObject
.
- Returns:
- the element or the specified
defaultValue
if not found.
- Throws:
CantConvertException
- if an existing element can't be converted to the
required type.
-
getJsonObjectOrEmpty
JsonObject getJsonObjectOrEmpty(int index)
throws CantConvertException
Gets an element as JsonObject
.
- Returns:
- the element or an empty
JsonObject
if not found
or if null
.
- Throws:
CantConvertException
- if an existing element can't be converted to the
required type.
-
getJsonArray
JsonArray getJsonArray(int index)
throws CantConvertException
Gets an element as JsonArray
.
- Returns:
- the element or
null
if not found.
- Throws:
CantConvertException
- if an existing element can't be converted to the
required type.
-
getJsonArray
JsonArray getJsonArray(int index,
JsonArray defaultValue)
throws CantConvertException
Gets an element as JsonArray
.
- Returns:
- the element or the specified
defaultValue
if not found.
- Throws:
CantConvertException
- if an existing element can't be converted to the
required type.
-
getJsonArrayOrEmpty
JsonArray getJsonArrayOrEmpty(int index)
throws CantConvertException
Gets an element as JsonArray
.
- Returns:
- the element or an empty
JsonArray
if not found or if null
.
- Throws:
CantConvertException
- if an existing element can't be converted to the
required type.
-
getString
String getString(int index)
Gets an element as String
.
- Returns:
- the element or
null
if not found.
-
getString
String getString(int index,
String defaultValue)
Gets an element as String
.
- Returns:
- the element or the specified
defaultValue
if not found.
-
getInteger
Integer getInteger(int index)
throws CantConvertException
Gets an element as Integer
.
- Returns:
- the element or
null
if not found.
- Throws:
CantConvertException
- if an existing element can't be converted to the
required type.
-
getInteger
Integer getInteger(int index,
Integer defaultValue)
throws CantConvertException
Gets an element as Integer
.
- Returns:
- the element or the specified
defaultValue
if not found.
- Throws:
CantConvertException
- if an existing element can't be converted to the
required type.
-
getLong
Long getLong(int index)
throws CantConvertException
Gets an element as Long
.
- Returns:
- the element or
null
if not found.
- Throws:
CantConvertException
- if an existing element can't be converted to the
required type.
-
getLong
Long getLong(int index,
Long defaultValue)
throws CantConvertException
Gets an element as Long
.
- Returns:
- the element or the specified
defaultValue
if not found.
- Throws:
CantConvertException
- if an existing element can't be converted to the
required type.
-
getFloat
Float getFloat(int index)
throws CantConvertException
Gets an element as Float
.
- Returns:
- the element or
null
if not found.
- Throws:
CantConvertException
- if an existing element can't be converted to the
required type.
-
getFloat
Float getFloat(int index,
Float defaultValue)
throws CantConvertException
Gets an element as Float
.
- Returns:
- the element or the specified
defaultValue
if not found.
- Throws:
CantConvertException
- if an existing element can't be converted to the
required type.
-
getDouble
Double getDouble(int index)
throws CantConvertException
Gets an element as Double
.
- Returns:
- the element or
null
if not found.
- Throws:
CantConvertException
- if an existing element can't be converted to the
required type.
-
getDouble
Double getDouble(int index,
Double defaultValue)
throws CantConvertException
Gets an element as Double
.
- Returns:
- the element or the specified
defaultValue
if not found.
- Throws:
CantConvertException
- if an existing element can't be converted to the
required type.
-
getBoolean
Boolean getBoolean(int index)
throws CantConvertException
Gets an element as Boolean
.
- Returns:
- the element or
null
if not found.
- Throws:
CantConvertException
- if an existing element can't be converted to the
required type.
-
getBoolean
Boolean getBoolean(int index,
Boolean defaultValue)
throws CantConvertException
Gets an element as Boolean
.
- Returns:
- the element or the specified
defaultValue
if not found.
- Throws:
CantConvertException
- if an existing element can't be converted to the
required type.
-
getBigDecimal
BigDecimal getBigDecimal(int index)
throws CantConvertException
Gets an element as BigDecimal
.
- Returns:
- the element or
null
if not found.
- Throws:
CantConvertException
- if an existing element can't be converted to the
required type.
-
getBigDecimal
BigDecimal getBigDecimal(int index,
BigDecimal defaultValue)
throws CantConvertException
Gets an element as BigDecimal
.
- Returns:
- the element or the specified
defaultValue
if not found.
- Throws:
CantConvertException
- if an existing element can't be converted to the
required type.
-
getBytesFromBase64String
byte[] getBytesFromBase64String(int index)
throws CantConvertException
Gets a byte array, from a base 64 encoded element.
- Returns:
- the element or
null
if not found.
- Throws:
CantConvertException
- if an existing element can't be converted to the
required type.
-
getBytesFromBase64String
byte[] getBytesFromBase64String(int index,
byte[] defaultValue)
throws CantConvertException
Gets a byte array, from a base 64 encoded element.
- Returns:
- the element or the specified
defaultValue
if not found.
- Throws:
CantConvertException
- if an existing element can't be converted to the
required type.
-
getDate
Date getDate(int index)
throws CantConvertException
Gets a UTC timezoned date from a ISO 8601
date element.
- Returns:
- the element or
null
if not found.
- Throws:
CantConvertException
- if an existing element can't be converted to the
required type.
-
getDate
Date getDate(int index,
Date defaultValue)
throws CantConvertException
Gets a UTC timezoned date from a ISO 8601
date element.
- Returns:
- the element or the specified
defaultValue
if not found.
- Throws:
CantConvertException
- if an existing element can't be converted to the
required type.
-
getInstant
Instant getInstant(int index)
throws CantConvertException
Gets an Instant from a ISO 8601
date element.
- Returns:
- the element or
null
if not found.
- Throws:
CantConvertException
- if an existing element can't be converted to the
required type.
-
getInstant
Instant getInstant(int index,
Instant defaultValue)
throws CantConvertException
Gets an Instant from a ISO 8601
date element.
- Returns:
- the element or the specified
defaultValue
if not found.
- Throws:
CantConvertException
- if an existing element can't be converted to the
required type.
-
getObject
Object getObject(int index)
Gets an element, untyped.
- Returns:
- the object or
null
if not found. This object
will necessarly be of a type managed by JsonArray
, since
an object of any other type is automatically converted when added.
-
getObject
Object getObject(int index,
Object defaultValue)
Gets an element, untyped.
- Returns:
- the object or the specified
defaultValue
if not found. This object
will necessarly be of a type managed by JsonArray
, since
an object of any other type is automatically converted when added.
-
getArrayFirstJsonObject
JsonObject getArrayFirstJsonObject(int index)
throws CantConvertException
Gets the first element (as JsonObject) of a JsonArray
element.
- Returns:
- the element or
null
if the array or
the first element are not found.
- Throws:
CantConvertException
- if an existing element can't be converted to the
required type.
-
getArrayFirstJsonObject
JsonObject getArrayFirstJsonObject(int index,
JsonObject defaultValue)
throws CantConvertException
Gets the first element (as JsonObject) of a JsonArray
element.
- Returns:
- the element or the specified
defaultValue
if the array or
the first element are not found.
- Throws:
CantConvertException
- if an existing element can't be converted to the
required type.
-
getArrayFirstJsonArray
JsonArray getArrayFirstJsonArray(int index)
throws CantConvertException
Gets the first element (as JsonArray) of a JsonArray
element.
- Returns:
- the element or
null
if the array or
the first element are not found.
- Throws:
CantConvertException
- if an existing element can't be converted to the
required type.
-
getArrayFirstJsonArray
JsonArray getArrayFirstJsonArray(int index,
JsonArray defaultValue)
throws CantConvertException
Gets the first element (as JsonArray) of a JsonArray
element.
- Returns:
- the element or the specified
defaultValue
if the array or
the first element are not found.
- Throws:
CantConvertException
- if an existing element can't be converted to the
required type.
-
getArrayFirstString
String getArrayFirstString(int index)
throws CantConvertException
Gets the first element (as String) of a JsonArray
element.
- Returns:
- the element or
null
if the array or
the first element are not found.
- Throws:
CantConvertException
- if an existing element can't be converted to the
required type.
-
getArrayFirstString
String getArrayFirstString(int index,
String defaultValue)
throws CantConvertException
Gets the first element (as String) of a JsonArray
element.
- Returns:
- the element or the specified
defaultValue
if the array or
the first element are not found.
- Throws:
CantConvertException
- if an existing element can't be converted to the
required type.
-
getArrayFirstInteger
Integer getArrayFirstInteger(int index)
throws CantConvertException
Gets the first element (as Integer) of a JsonArray
element.
- Returns:
- the element or
null
if the array or
the first element are not found.
- Throws:
CantConvertException
- if an existing element can't be converted to the
required type.
-
getArrayFirstInteger
Integer getArrayFirstInteger(int index,
Integer defaultValue)
throws CantConvertException
Gets the first element (as Integer) of a JsonArray
element.
- Returns:
- the element or the specified
defaultValue
if the array or
the first element are not found.
- Throws:
CantConvertException
- if an existing element can't be converted to the
required type.
-
getArrayFirstLong
Long getArrayFirstLong(int index)
throws CantConvertException
Gets the first element (as Long) of a JsonArray
element.
- Returns:
- the element or
null
if the array or
the first element are not found.
- Throws:
CantConvertException
- if an existing element can't be converted to the
required type.
-
getArrayFirstLong
Long getArrayFirstLong(int index,
Long defaultValue)
throws CantConvertException
Gets the first element (as Long) of a JsonArray
element.
- Returns:
- the element or the specified
defaultValue
if the array or
the first element are not found.
- Throws:
CantConvertException
- if an existing element can't be converted to the
required type.
-
getArrayFirstDouble
Double getArrayFirstDouble(int index)
throws CantConvertException
Gets the first element (as Double) of a JsonArray
element.
- Returns:
- the element or
null
if the array or
the first element are not found.
- Throws:
CantConvertException
- if an existing element can't be converted to the
required type.
-
getArrayFirstDouble
Double getArrayFirstDouble(int index,
Double defaultValue)
throws CantConvertException
Gets the first element (as Double) of a JsonArray
element.
- Returns:
- the element or the specified
defaultValue
if the array or
the first element are not found.
- Throws:
CantConvertException
- if an existing element can't be converted to the
required type.
-
getArrayFirstFloat
Float getArrayFirstFloat(int index)
throws CantConvertException
Gets the first element (as Float) of a JsonArray
element.
- Returns:
- the element or
null
if the array or
the first element are not found.
- Throws:
CantConvertException
- if an existing element can't be converted to the
required type.
-
getArrayFirstFloat
Float getArrayFirstFloat(int index,
Float defaultValue)
throws CantConvertException
Gets the first element (as Float) of a JsonArray
element.
- Returns:
- the element or the specified
defaultValue
if the array or
the first element are not found.
- Throws:
CantConvertException
- if an existing element can't be converted to the
required type.
-
getArrayFirstBoolean
Boolean getArrayFirstBoolean(int index)
throws CantConvertException
Gets the first element (as Boolean) of a JsonArray
element.
- Returns:
- the element or
null
if the array or
the first element are not found.
- Throws:
CantConvertException
- if an existing element can't be converted to the
required type.
-
getArrayFirstBoolean
Boolean getArrayFirstBoolean(int index,
Boolean defaultValue)
throws CantConvertException
Gets the first element (as Boolean) of a JsonArray
element.
- Returns:
- the element or the specified
defaultValue
if the array or
the first element are not found.
- Throws:
CantConvertException
- if an existing element can't be converted to the
required type.
-
getArrayFirstBigDecimal
BigDecimal getArrayFirstBigDecimal(int index)
throws CantConvertException
Gets the first element (as BigDecimal) of a JsonArray
element.
- Returns:
- the element or
null
if the array or
the first element are not found.
- Throws:
CantConvertException
- if an existing element can't be converted to the
required type.
-
getArrayFirstBigDecimal
BigDecimal getArrayFirstBigDecimal(int index,
BigDecimal defaultValue)
throws CantConvertException
Gets the first element (as BigDecimal) of a JsonArray
element.
- Returns:
- the element or the specified
defaultValue
if the array or
the first element are not found.
- Throws:
CantConvertException
- if an existing element can't be converted to the
required type.
-
getArrayFirstBytesFromBase64String
byte[] getArrayFirstBytesFromBase64String(int index)
throws CantConvertException
Gets the first element (as byte[]) of a JsonArray
element.
- Returns:
- the element or
null
if the array or
the first element are not found.
- Throws:
CantConvertException
- if an existing element can't be converted to the
required type.
-
getArrayFirstBytesFromBase64String
byte[] getArrayFirstBytesFromBase64String(int index,
byte[] defaultValue)
throws CantConvertException
Gets the first element (as byte[]) of a JsonArray
element.
- Returns:
- the element or the specified
defaultValue
if the array or
the first element are not found.
- Throws:
CantConvertException
- if an existing element can't be converted to the
required type.
-
getArrayFirstDate
Date getArrayFirstDate(int index)
throws CantConvertException
Gets the first element (as Date) of a JsonArray
element.
- Returns:
- the element or
null
if the array or
the first element are not found.
- Throws:
CantConvertException
- if an existing element can't be converted to the
required type.
-
getArrayFirstDate
Date getArrayFirstDate(int index,
Date defaultValue)
throws CantConvertException
Gets the first element (as Date) of a JsonArray
element.
- Returns:
- the element or the specified
defaultValue
if the array or
the first element are not found.
- Throws:
CantConvertException
- if an existing element can't be converted to the
required type.
-
getArrayFirstInstant
Instant getArrayFirstInstant(int index)
throws CantConvertException
Gets the first element (as Instant) of a JsonArray
element.
- Returns:
- the element or
null
if the array or
the first element are not found.
- Throws:
CantConvertException
- if an existing element can't be converted to the
required type.
-
getArrayFirstInstant
Instant getArrayFirstInstant(int index,
Instant defaultValue)
throws CantConvertException
Gets the first element (as Instant) of a JsonArray
element.
- Returns:
- the element or the specified
defaultValue
if the array or
the first element are not found.
- Throws:
CantConvertException
- if an existing element can't be converted to the
required type.
-
isCanBeConvertedToString
boolean isCanBeConvertedToString(int index)
Validates that the element at the specified index
exists and
is currently null
, of type String
, or can be
converted and retrieved as one.
-
isCanBeConvertedToInteger
boolean isCanBeConvertedToInteger(int index)
Validates that the element at the specified index
exists and
is currently null
, of type Integer
, or can be
converted and retrieved as one.
-
isCanBeConvertedToLong
boolean isCanBeConvertedToLong(int index)
Validates that the element at the specified index
exists and
is currently null
, of type Long
, or can be
converted and retrieved as one.
-
isCanBeConvertedToFloat
boolean isCanBeConvertedToFloat(int index)
Validates that the element at the specified index
exists and
is currently null
, of type Float
, or can be
converted and retrieved as one.
-
isCanBeConvertedToDouble
boolean isCanBeConvertedToDouble(int index)
Validates that the element at the specified index
exists and
is currently null
, of type Double
, or can be
converted and retrieved as one.
-
isCanBeConvertedToBoolean
boolean isCanBeConvertedToBoolean(int index)
Validates that the element at the specified index
exists and
is currently null
, of type Boolean
, or can be
converted and retrieved as one.
-
isCanBeConvertedToBigDecimal
boolean isCanBeConvertedToBigDecimal(int index)
Validates that the element at the specified index
exists and
is currently null
, of type BigDecimal
, or can be
converted and retrieved as one.
-
isCanBeConvertedToByteArray
boolean isCanBeConvertedToByteArray(int index)
Validates that the element at the specified index
exists and
is currently null
, of type base 64 String
representing
a byte array, or can be converted and retrieved as one.
-
isCanBeConvertedToDate
boolean isCanBeConvertedToDate(int index)
Validates that the element at the specified index
exists and
is currently null
, of type Date
, or can be
converted and retrieved as one.
-
isCanBeConvertedToJsonObject
boolean isCanBeConvertedToJsonObject(int index)
Validates that the element at the specified index
exists and
is currently null
, of type JsonObject
, or can be
converted and retrieved as one.
-
isCanBeConvertedToJsonArray
boolean isCanBeConvertedToJsonArray(int index)
Validates that the element at the specified index
exists and
is currently null
, of type JsonArray
, or can be
converted and retrieved as one.
-
isOfTypeString
boolean isOfTypeString(int index)
Validates that the element at the specified index
exists and
is currently null
or of type String
, without requiring
any conversion.
-
isOfTypeInteger
boolean isOfTypeInteger(int index)
Validates that the element at the specified index
exists and
is currently null
or of type Integer
, without requiring
any conversion.
-
isOfTypeLong
boolean isOfTypeLong(int index)
Validates that the element at the specified index
exists and
is currently null
or of type Long
, without requiring
any conversion.
-
isOfTypeFloat
boolean isOfTypeFloat(int index)
Validates that the element at the specified index
exists and
is currently null
or of type Float
, without requiring
any conversion.
-
isOfTypeDouble
boolean isOfTypeDouble(int index)
Validates that the element at the specified index
exists and
is currently null
or of type Double
, without requiring
any conversion.
-
isOfTypeBoolean
boolean isOfTypeBoolean(int index)
Validates that the element at the specified index
exists and
is currently null
or of type Boolean
, without requiring
any conversion.
-
isOfTypeBigDecimal
boolean isOfTypeBigDecimal(int index)
Validates that the element at the specified index
exists and
is currently null
or of type BigDecimal
, without requiring
any conversion.
-
isOfTypeByteArray
boolean isOfTypeByteArray(int index,
boolean acceptBase64StringToo)
Validates that the element at the specified JsonPath
exists and
is currently null
or of type byte[]
, without requiring
any conversion.
- Parameters:
acceptBase64StringToo
- if true
, then a valid base 64 String
will also be accepted.
-
isOfTypeDate
boolean isOfTypeDate(int index)
Validates that the element at the specified index
exists and
is currently null
or of type Date
, without requiring
any conversion.
-
isOfTypeJsonObject
boolean isOfTypeJsonObject(int index)
Validates that the element at the specified index
exists and
is currently null
or of type JsonObject
, without requiring
any conversion.
-
isOfTypeJsonArray
boolean isOfTypeJsonArray(int index)
Validates that the element at the specified index
exists and
is currently null
or of type JsonArray
, without requiring
any conversion.
-
isNull
boolean isNull(int index)
Validates that there is an element at the specified index
and
it is null
.
-
isEquivalentTo
boolean isEquivalentTo(JsonArray other)
Compares the current JsonArray
to the specified one
and returns true
if they are equivalent. To be equivalent,
all their elements must be so too.
An element is equivalent to the other if they can be converted to the¸
same type, and then if they are equals.
For example, the String
"123" is equivalent to
new BigDecimal("123")
or to 123L
.
-
clone
JsonArray clone(boolean mutable)
Deep copy of the JsonArray
, so any
modification to the original won't affect the
clone, and vice-versa.
Note that if the current array is immutable and
the mutable
parameter is set to false
,
then the current array will be returned as is since no
cloning is then required.
- Specified by:
clone
in interface JsonObjectOrArray
- Parameters:
mutable
- if true
the resulting
array and all its children will be mutable, otherwise
they will all be immutable.
-
transform
void transform(int index,
ElementTransformer transformer)
Transforms the element at the given index, using the
specified ElementTransformer
.
-
trim
void trim(int index)
Trims the element, if it's of type String
.
-
convertToStringList
List<String> convertToStringList()
Converts the JsonArray to a List<String>
.
To do so, the toString()
method will be called
on any non null element.
This list is always a new instance and is mutable.
Copyright © 2019. All rights reserved.