public interface OracleJsonArray extends OracleJsonStructure, List<OracleJsonValue>
OracleJsonValue
which includes the extended
SQL types such as OracleJsonTimestamp
.
Instances of OracleJsonArray
may either be mutable or immutable. When
an instance is immutable, calling methods that would mutate the array will
throw UnsupportedOperationException
. For example,
OracleJsonArray
instances that are returned from a
ResultSet
are immutable.
Instances that are returned from OracleJsonFactory.createArray()
and
OracleJsonFactory.createArray(OracleJsonArray)
methods are mutable.
import oracle.sql.json.OracleJsonArray;
import oracle.sql.json.OracleJsonFactory;
public class JsonArrayExample {
public static void main(String[] args) {
OracleJsonFactory factory = new OracleJsonFactory();
OracleJsonArray arr = factory.createArray();
arr.add("hello");
arr.add(123);
arr.add(true);
System.out.println(arr.toString());
System.out.println(arr.getInt(1));
}
}
Running this example prints:
["hello",123,true] 123
OracleJsonValue.OracleJsonType
FALSE, NULL, TRUE
Modifier and Type | Method and Description |
---|---|
void |
add(BigDecimal value)
Appends the specified decimal to the end of this array.
|
void |
add(boolean value)
Appends the specified
boolean to the end of this array. |
void |
add(byte[] value)
Appends the specified byte array to the end of this array.
|
void |
add(double value)
Appends the specified
double to the end of this array. |
void |
add(int value)
Appends the specified
integer to the end of this array. |
void |
add(java.time.LocalDateTime value)
Appends the specified LocalDateTime to the end of this array.
|
void |
add(long value)
Appends the specified
long to the end of this array. |
void |
add(java.time.OffsetDateTime value)
Appends the specified OffsetDateTime to the end of this array.
|
void |
add(String value)
Appends the specified string to the end of this array.
|
void |
addNull()
Appends
OracleJsonValue.NULL to the end of
this array. |
BigDecimal |
getBigDecimal(int index)
Returns the double at the specified position in the JSON array.
|
boolean |
getBoolean(int index)
Returns the boolean at the specified position in the JSON array.
|
byte[] |
getBytes(int index)
Returns the binary value at the specified position in the JSON array.
|
double |
getDouble(int index)
Returns the double at the specified position in the JSON array.
|
int |
getInt(int index)
Returns the int at the specified position in the JSON array.
|
java.time.LocalDateTime |
getLocalDateTime(int index)
Returns the timestamp or date value at the specified position in the JSON
array.
|
long |
getLong(int index)
Returns the long at the specified position in the JSON array.
|
java.time.OffsetDateTime |
getOffsetDateTime(int index)
Returns the timestamptz value at the specified position in the JSON
array.
|
String |
getString(int index)
Returns the string at the specified position in the JSON array.
|
<T extends OracleJsonValue> |
getValuesAs(Class<T> c)
Returns a view of this array for the given element type.
|
boolean |
isNull(int index)
Returns
true if the value at the specified position in the array
is equal to JsonValue.NULL . |
OracleJsonValue |
set(int index,
BigDecimal value)
Replaces the value at the specified position in the array with the
specified decimal value.
|
OracleJsonValue |
set(int index,
boolean value)
Replaces the value at the specified position in the array with the
specified
boolean . |
OracleJsonValue |
set(int index,
byte[] value)
Replaces the value at the specified position in the array with the
specified byte array.
|
OracleJsonValue |
set(int index,
double value)
Replaces the value at the specified position in the array with the
specified
double . |
OracleJsonValue |
set(int index,
int value)
Replaces the value at the specified position in the array with the
specified integer.
|
OracleJsonValue |
set(int index,
java.time.LocalDateTime value)
Replaces the value at the specified position in the array with the
specified
LocalDateTime . |
OracleJsonValue |
set(int index,
long value)
Replaces the value at the specified position in the array with the
specified
long . |
OracleJsonValue |
set(int index,
java.time.OffsetDateTime value)
Replaces the value at the specified position in the array with the
specified
OffsetDateTime . |
OracleJsonValue |
set(int index,
String value)
Replaces the value at the specified position in the array with the
specified string.
|
OracleJsonValue |
setNull(int index)
Replaces the value at the specified position in the array with
OracleJsonValue.NULL . |
asJsonArray, asJsonBinary, asJsonDate, asJsonDecimal, asJsonDouble, asJsonFloat, asJsonIntervalDS, asJsonIntervalYM, asJsonNumber, asJsonObject, asJsonString, asJsonTimestamp, asJsonTimestampTZ, getOracleJsonType, toString, wrap
add, add, addAll, addAll, clear, contains, containsAll, equals, get, hashCode, indexOf, isEmpty, iterator, lastIndexOf, listIterator, listIterator, remove, remove, removeAll, replaceAll, retainAll, set, size, sort, spliterator, subList, toArray, toArray
parallelStream, removeIf, stream
String getString(int index)
get(index).asJsonString().getString()
.index
- the index of the JSON string valueIndexOutOfBoundsException
- if the index is out of rangeClassCastException
- if the value at the specified position is not an
instance of OracleJsonStringint getInt(int index)
((OracleJsonNumber)get(index)).intValue()
.index
- the index of the JSON valueIndexOutOfBoundsException
- if the index is out of rangeClassCastException
- if the value at the specified position is not an
instance of OracleJsonNumberdouble getDouble(int index)
((OracleJsonNumber)get(index)).doubleValue()
.index
- the index of the JSON valueIndexOutOfBoundsException
- if the index is out of rangeClassCastException
- if the value at the specified position is not an
instance of OracleJsonNumberBigDecimal getBigDecimal(int index)
((OracleJsonNumber)get(index)).bigDecimalValue()
.index
- the index of the JSON valueIndexOutOfBoundsException
- if the index is out of rangeClassCastException
- if the value at the specified position is not an
instance of OracleJsonNumberlong getLong(int index)
((OracleJsonNumber)get(index)).longValue()
.index
- the index of the JSON valueIndexOutOfBoundsException
- if the index is out of rangeClassCastException
- if the value at the specified position is not an
instance of OracleJsonNumberboolean getBoolean(int index)
true
if the value at the specified position
is equal to OracleJsonValue.TRUE
and false
if the value at
the specified position is equal to OracleJsonValue.FALSE
.index
- the index of the JSON valueIndexOutOfBoundsException
- if the index is out of rangeClassCastException
- if the value at the specified position is not
equal to OracleJsonValue.TRUE
or OracleJson.FALSE
.boolean isNull(int index)
true
if the value at the specified position in the array
is equal to JsonValue.NULL
.index
- the index of the JSON valueIndexOutOfBoundsException
- if the index is out of rangebyte[] getBytes(int index)
get(index).asJsonBinary().getBytes()
.index
- the index of the JSON valueIndexOutOfBoundsException
- if the index is out of rangeClassCastException
- if the value at the specified position is not an
instance of OracleJsonBinaryjava.time.LocalDateTime getLocalDateTime(int index)
get(index).asJsonDate().getLocalDateTime()
or
get(index).asJsonTimestamp().getLocalDateTime()
depending
if the value is a date or a timestamp.index
- the index of the JSON valueIndexOutOfBoundsException
- if the index is out of rangeClassCastException
- if the value at the specified position is not an
instance of OracleJsonTimestamp or OracleJsonDate.java.time.OffsetDateTime getOffsetDateTime(int index)
get(index).asJsonTimestampTZ().getOffsetDateTime()
.index
- the index of the JSON valueIndexOutOfBoundsException
- if the index is out of rangeClassCastException
- if the value at the specified position is not an
instance of OracleJsonDateTime.OracleJsonValue set(int index, String value)
OracleJsonString
.index
- the index of the JSON value to replaceNullPointerException
- if the specified value is nullIndexOutOfBoundsException
- if the index is out of rangeUnsupportedOperationException
- if the set operation is not supportedOracleJsonValue set(int index, int value)
int
is added to the array as an instance
of OracleJsonDecimal
.index
- the index of the JSON value to replacevalue
- the value to be set at the specified positionNullPointerException
- if the specified value is nullIndexOutOfBoundsException
- if the index is out of rangeUnsupportedOperationException
- if the set operation is not supportedOracleJsonValue set(int index, double value)
double
. The new double
is added to the array as
an instance of OracleJsonDouble
.index
- the index of the JSON value to replacevalue
- the value to be set at the specified positionNullPointerException
- if the specified value is nullIndexOutOfBoundsException
- if the index is out of rangeUnsupportedOperationException
- if the set operation is not supportedOracleJsonValue set(int index, long value)
long
. The new long
is added to the array as
an instance of OracleJsonDecimal
.index
- the index of the JSON value to replacevalue
- the value to be set at the specified positionNullPointerException
- if the specified value is nullIndexOutOfBoundsException
- if the index is out of rangeUnsupportedOperationException
- if the set operation is not supportedOracleJsonValue set(int index, BigDecimal value) throws OracleJsonException
OracleJsonDecimal
.index
- the index of the JSON value to replacevalue
- the value to be set at the specified positionNullPointerException
- if the specified value is nullIndexOutOfBoundsException
- if the index is out of rangeOracleJsonException
- if the value can not be converted to OracleJsonDecimalUnsupportedOperationException
- if the set operation is not supportedOracleJsonValue set(int index, boolean value)
boolean
. If the specified value is true, then
OracleJsonValue.TRUE
is added and otherwise
OracleJsonValue.FALSE
.index
- the index of the JSON value to replacevalue
- the value to be set at the specified positionNullPointerException
- if the specified value is nullIndexOutOfBoundsException
- if the index is out of rangeUnsupportedOperationException
- if the set operation is not supportedOracleJsonValue setNull(int index)
OracleJsonValue.NULL
.index
- the index of the JSON value to replaceIndexOutOfBoundsException
- if the index is out of rangeUnsupportedOperationException
- if the set operation is not supportedOracleJsonValue set(int index, java.time.LocalDateTime value)
LocalDateTime
. The LocalDateTime
is added to the array as
an instance of OracleJsonTimestamp
.index
- the index of the JSON value to replacevalue
- the value to be set at the specified positionNullPointerException
- if the specified value is nullIndexOutOfBoundsException
- if the index is out of rangeUnsupportedOperationException
- if the set operation is not supportedOracleJsonValue set(int index, java.time.OffsetDateTime value)
OffsetDateTime
. The OffsetDateTime
is added to the array as
an instance of OracleJsonTimestampTZ
.index
- the index of the JSON value to replacevalue
- the value to be set at the specified positionNullPointerException
- if the specified value is nullIndexOutOfBoundsException
- if the index is out of rangeUnsupportedOperationException
- if the set operation is not supportedOracleJsonValue set(int index, byte[] value)
OracleJsonBinary
.index
- the index of the JSON value to replacevalue
- the value to be set at the specified positionNullPointerException
- if the specified value is nullIndexOutOfBoundsException
- if the index is out of rangeUnsupportedOperationException
- if the set operation is not supportedvoid add(String value)
OracleJsonString
.value
- the value to be appended to this arrayNullPointerException
- if the specified value is nullUnsupportedOperationException
- if the set operation is not supportedvoid add(int value)
integer
to the end of this array. The
int
is appended to the array as an instance of
OracleJsonDecimal
.value
- the value to be appended to this arrayNullPointerException
- if the specified value is nullUnsupportedOperationException
- if the set operation is not supportedvoid add(double value)
double
to the end of this array. The
double
is appended to the array as an instance of
OracleJsonDouble
.value
- the value to be appended to this arrayNullPointerException
- if the specified value is nullUnsupportedOperationException
- if the set operation is not supportedvoid add(long value)
long
to the end of this array. The
long
is appended to the array as an instance of
OracleJsonDecimal
.value
- the value to be appended to this arrayNullPointerException
- if the specified value is nullUnsupportedOperationException
- if the set operation is not supportedvoid add(BigDecimal value)
OracleJsonDecimal
.value
- the value to be appended to this arrayNullPointerException
- if the specified value is nullUnsupportedOperationException
- if the set operation is not supportedvoid add(boolean value)
boolean
to the end of this array. If the
specified value is true then OracleJsonValue.TRUE
is appended to the list and otherwise
OracleJsonValue.FALSE
.value
- the value to be appended to this arrayNullPointerException
- if the specified value is nullUnsupportedOperationException
- if the set operation is not supportedvoid addNull()
OracleJsonValue.NULL
to the end of
this array.UnsupportedOperationException
- if the set operation is not supportedvoid add(java.time.LocalDateTime value)
LocalDateTime
is appended to the array as an instance of OracleJsonTimestamp
.value
- the value to be appended to this arrayNullPointerException
- if the specified value is nullUnsupportedOperationException
- if the set operation is not supportedvoid add(java.time.OffsetDateTime value)
OffsetDateTime
is appended to the array as an instance of OracleJsonTimestampTZ
.value
- the value to be appended to this arrayNullPointerException
- if the specified value is nullUnsupportedOperationException
- if the set operation is not supportedvoid add(byte[] value)
OracleJsonBinary
.value
- the value to be appended to this arrayNullPointerException
- if the specified value is nullUnsupportedOperationException
- if the set operation is not supported<T extends OracleJsonValue> List<T> getValuesAs(Class<T> c)
c
- a subtype of OracleJsonValue