Package oracle.sql.json
Interface OracleJsonArray
- All Superinterfaces:
Collection<OracleJsonValue>,Iterable<OracleJsonValue>,List<OracleJsonValue>,OracleJsonStructure,OracleJsonValue
A JSON array (an ordered sequence of zero or more values). The object may
contain any subtype of
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
-
Nested Class Summary
Nested classes/interfaces inherited from interface oracle.sql.json.OracleJsonValue
OracleJsonValue.OracleJsonType -
Field Summary
Fields inherited from interface oracle.sql.json.OracleJsonValue
FALSE, NULL, TRUE -
Method Summary
Modifier and TypeMethodDescriptionvoidadd(boolean value) Appends the specifiedbooleanto the end of this array.voidadd(byte[] value) Appends the specified byte array to the end of this array.voidadd(double value) Appends the specifieddoubleto the end of this array.voidadd(int value) Appends the specifiedintegerto the end of this array.voidadd(long value) Appends the specifiedlongto the end of this array.voidAppends the specified string to the end of this array.voidadd(BigDecimal value) Appends the specified decimal to the end of this array.voidadd(LocalDateTime value) Appends the specified LocalDateTime to the end of this array.voidadd(OffsetDateTime value) Appends the specified OffsetDateTime to the end of this array.voidaddNull()AppendsOracleJsonValue.NULLto the end of this array.default OracleJsonArraygetArray(int index) Returns the array at the specified position in the JSON array.getBigDecimal(int index) Returns the double at the specified position in the JSON array.booleangetBoolean(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.doublegetDouble(int index) Returns the double at the specified position in the JSON array.intgetInt(int index) Returns the int at the specified position in the JSON array.getLocalDateTime(int index) Returns the timestamp or date value at the specified position in the JSON array.longgetLong(int index) Returns the long at the specified position in the JSON array.default OracleJsonObjectgetObject(int index) Returns the object at the specified position in the JSON array.getOffsetDateTime(int index) Returns the timestamptz value at the specified position in the JSON array.getString(int index) Returns the string at the specified position in the JSON array.<T extends OracleJsonValue>
List<T>getValuesAs(Class<T> c) Returns a view of this array for the given element type.booleanisNull(int index) Returnstrueif the value at the specified position in the array is equal toJsonValue.NULL.set(int index, boolean value) Replaces the value at the specified position in the array with the specifiedboolean.set(int index, byte[] value) Replaces the value at the specified position in the array with the specified byte array.set(int index, double value) Replaces the value at the specified position in the array with the specifieddouble.set(int index, int value) Replaces the value at the specified position in the array with the specified integer.set(int index, long value) Replaces the value at the specified position in the array with the specifiedlong.Replaces the value at the specified position in the array with the specified string.set(int index, BigDecimal value) Replaces the value at the specified position in the array with the specified decimal value.set(int index, LocalDateTime value) Replaces the value at the specified position in the array with the specifiedLocalDateTime.set(int index, OffsetDateTime value) Replaces the value at the specified position in the array with the specifiedOffsetDateTime.setNull(int index) Replaces the value at the specified position in the array withOracleJsonValue.NULL.Methods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArrayMethods inherited from interface java.util.List
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, toArrayMethods inherited from interface oracle.sql.json.OracleJsonValue
asJsonArray, asJsonBinary, asJsonDate, asJsonDecimal, asJsonDouble, asJsonFloat, asJsonIntervalDS, asJsonIntervalYM, asJsonNumber, asJsonObject, asJsonString, asJsonTimestamp, asJsonTimestampTZ, asJsonVector, getOracleJsonType, toString, wrap
-
Method Details
-
getString
Returns the string at the specified position in the JSON array. This is a convenience method that is equivalent toget(index).asJsonString().getString().- Parameters:
index- the index of the JSON string value- Returns:
- the string value
- Throws:
IndexOutOfBoundsException- if the index is out of rangeClassCastException- if the value at the specified position is not an instance of OracleJsonString
-
getInt
int getInt(int index) Returns the int at the specified position in the JSON array. This is a convenience method that is equivalent to((OracleJsonNumber)get(index)).intValue().- Parameters:
index- the index of the JSON value- Returns:
- the int value
- Throws:
IndexOutOfBoundsException- if the index is out of rangeClassCastException- if the value at the specified position is not an instance of OracleJsonNumber
-
getDouble
double getDouble(int index) Returns the double at the specified position in the JSON array. This is a convenience method that is equivalent to((OracleJsonNumber)get(index)).doubleValue().- Parameters:
index- the index of the JSON value- Returns:
- the double value
- Throws:
IndexOutOfBoundsException- if the index is out of rangeClassCastException- if the value at the specified position is not an instance of OracleJsonNumber
-
getBigDecimal
Returns the double at the specified position in the JSON array. This is a convenience method that is equivalent to((OracleJsonNumber)get(index)).bigDecimalValue().- Parameters:
index- the index of the JSON value- Returns:
- the BigDecimal value
- Throws:
IndexOutOfBoundsException- if the index is out of rangeClassCastException- if the value at the specified position is not an instance of OracleJsonNumber
-
getLong
long getLong(int index) Returns the long at the specified position in the JSON array. This is a convenience method that is equivalent to((OracleJsonNumber)get(index)).longValue().- Parameters:
index- the index of the JSON value- Returns:
- the long value
- Throws:
IndexOutOfBoundsException- if the index is out of rangeClassCastException- if the value at the specified position is not an instance of OracleJsonNumber
-
getBoolean
boolean getBoolean(int index) Returns the boolean at the specified position in the JSON array. Specifically, returnstrueif the value at the specified position is equal toOracleJsonValue.TRUEandfalseif the value at the specified position is equal toOracleJsonValue.FALSE.- Parameters:
index- the index of the JSON value- Returns:
- the boolean value
- Throws:
IndexOutOfBoundsException- if the index is out of rangeClassCastException- if the value at the specified position is not equal toOracleJsonValue.TRUEorOracleJson.FALSE.
-
isNull
boolean isNull(int index) Returnstrueif the value at the specified position in the array is equal toJsonValue.NULL.- Parameters:
index- the index of the JSON value- Returns:
- the boolean value
- Throws:
IndexOutOfBoundsException- if the index is out of range
-
getBytes
byte[] getBytes(int index) Returns the binary value at the specified position in the JSON array. This is a convenience method that is equivalent toget(index).asJsonBinary().getBytes().- Parameters:
index- the index of the JSON value- Returns:
- the binary value
- Throws:
IndexOutOfBoundsException- if the index is out of rangeClassCastException- if the value at the specified position is not an instance of OracleJsonBinary
-
getLocalDateTime
Returns the timestamp or date value at the specified position in the JSON array. The method is equivalent toget(index).asJsonDate().getLocalDateTime()orget(index).asJsonTimestamp().getLocalDateTime()depending if the value is a date or a timestamp.- Parameters:
index- the index of the JSON value- Returns:
- the string value
- Throws:
IndexOutOfBoundsException- if the index is out of rangeClassCastException- if the value at the specified position is not an instance of OracleJsonTimestamp or OracleJsonDate.
-
getOffsetDateTime
Returns the timestamptz value at the specified position in the JSON array. This is a convenience method that is equivalent toget(index).asJsonTimestampTZ().getOffsetDateTime().- Parameters:
index- the index of the JSON value- Returns:
- the string value
- Throws:
IndexOutOfBoundsException- if the index is out of rangeClassCastException- if the value at the specified position is not an instance of OracleJsonDateTime.
-
getObject
Returns the object at the specified position in the JSON array. This is a convenience method that is equivalent toget(index).asJsonObject().- Parameters:
index- the index of the JSON value- Returns:
- the string value
- Throws:
IndexOutOfBoundsException- if the index is out of rangeClassCastException- if the value at the specified position is not an instance of OracleJsonObject.
-
getArray
Returns the array at the specified position in the JSON array. This is a convenience method that is equivalent toget(index).asJsonArray().- Parameters:
index- the index of the JSON value- Returns:
- the string value
- Throws:
IndexOutOfBoundsException- if the index is out of rangeClassCastException- if the value at the specified position is not an instance of OracleJsonArray.
-
set
Replaces the value at the specified position in the array with the specified string. The new string is added to the array as an instance ofOracleJsonString.- Parameters:
index- the index of the JSON value to replace- Returns:
- the value previously at the specified position
- Throws:
NullPointerException- if the specified value is nullIndexOutOfBoundsException- if the index is out of rangeUnsupportedOperationException- if the set operation is not supported
-
set
Replaces the value at the specified position in the array with the specified integer. The newintis added to the array as an instance ofOracleJsonDecimal.- Parameters:
index- the index of the JSON value to replacevalue- the value to be set at the specified position- Returns:
- the value previously at the specified position
- Throws:
NullPointerException- if the specified value is nullIndexOutOfBoundsException- if the index is out of rangeUnsupportedOperationException- if the set operation is not supported
-
set
Replaces the value at the specified position in the array with the specifieddouble. The newdoubleis added to the array as an instance ofOracleJsonDouble.- Parameters:
index- the index of the JSON value to replacevalue- the value to be set at the specified position- Returns:
- the value previously at the specified position
- Throws:
NullPointerException- if the specified value is nullIndexOutOfBoundsException- if the index is out of rangeUnsupportedOperationException- if the set operation is not supported
-
set
Replaces the value at the specified position in the array with the specifiedlong. The newlongis added to the array as an instance ofOracleJsonDecimal.- Parameters:
index- the index of the JSON value to replacevalue- the value to be set at the specified position- Returns:
- the value previously at the specified position
- Throws:
NullPointerException- if the specified value is nullIndexOutOfBoundsException- if the index is out of rangeUnsupportedOperationException- if the set operation is not supported
-
set
Replaces the value at the specified position in the array with the specified decimal value. The new value is added to the array as an instance ofOracleJsonDecimal.- Parameters:
index- the index of the JSON value to replacevalue- the value to be set at the specified position- Returns:
- the value previously at the specified position
- Throws:
NullPointerException- 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 supported
-
set
Replaces the value at the specified position in the array with the specifiedboolean. If the specified value is true, thenOracleJsonValue.TRUEis added and otherwiseOracleJsonValue.FALSE.- Parameters:
index- the index of the JSON value to replacevalue- the value to be set at the specified position- Returns:
- the value previously at the specified position
- Throws:
NullPointerException- if the specified value is nullIndexOutOfBoundsException- if the index is out of rangeUnsupportedOperationException- if the set operation is not supported
-
setNull
Replaces the value at the specified position in the array withOracleJsonValue.NULL.- Parameters:
index- the index of the JSON value to replace- Returns:
- the value previously at the specified position
- Throws:
IndexOutOfBoundsException- if the index is out of rangeUnsupportedOperationException- if the set operation is not supported
-
set
Replaces the value at the specified position in the array with the specifiedLocalDateTime. TheLocalDateTimeis added to the array as an instance ofOracleJsonTimestamp.- Parameters:
index- the index of the JSON value to replacevalue- the value to be set at the specified position- Returns:
- the value previously at the specified position
- Throws:
NullPointerException- if the specified value is nullIndexOutOfBoundsException- if the index is out of rangeUnsupportedOperationException- if the set operation is not supported
-
set
Replaces the value at the specified position in the array with the specifiedOffsetDateTime. TheOffsetDateTimeis added to the array as an instance ofOracleJsonTimestampTZ.- Parameters:
index- the index of the JSON value to replacevalue- the value to be set at the specified position- Returns:
- the value previously at the specified position
- Throws:
NullPointerException- if the specified value is nullIndexOutOfBoundsException- if the index is out of rangeUnsupportedOperationException- if the set operation is not supported
-
set
Replaces the value at the specified position in the array with the specified byte array. The byte array is added to the array as an instance ofOracleJsonBinary.- Parameters:
index- the index of the JSON value to replacevalue- the value to be set at the specified position- Returns:
- the value previously at the specified position
- Throws:
NullPointerException- if the specified value is nullIndexOutOfBoundsException- if the index is out of rangeUnsupportedOperationException- if the set operation is not supported
-
add
Appends the specified string to the end of this array. The string is appended to the array as an instance ofOracleJsonString.- Parameters:
value- the value to be appended to this array- Throws:
NullPointerException- if the specified value is nullUnsupportedOperationException- if the set operation is not supported
-
add
void add(int value) Appends the specifiedintegerto the end of this array. Theintis appended to the array as an instance ofOracleJsonDecimal.- Parameters:
value- the value to be appended to this array- Throws:
NullPointerException- if the specified value is nullUnsupportedOperationException- if the set operation is not supported
-
add
void add(double value) Appends the specifieddoubleto the end of this array. Thedoubleis appended to the array as an instance ofOracleJsonDouble.- Parameters:
value- the value to be appended to this array- Throws:
NullPointerException- if the specified value is nullUnsupportedOperationException- if the set operation is not supported
-
add
void add(long value) Appends the specifiedlongto the end of this array. Thelongis appended to the array as an instance ofOracleJsonDecimal.- Parameters:
value- the value to be appended to this array- Throws:
NullPointerException- if the specified value is nullUnsupportedOperationException- if the set operation is not supported
-
add
Appends the specified decimal to the end of this array. The decimal is appended to the array as an instance ofOracleJsonDecimal.- Parameters:
value- the value to be appended to this array- Throws:
NullPointerException- if the specified value is nullUnsupportedOperationException- if the set operation is not supported
-
add
void add(boolean value) Appends the specifiedbooleanto the end of this array. If the specified value is true thenOracleJsonValue.TRUEis appended to the list and otherwiseOracleJsonValue.FALSE.- Parameters:
value- the value to be appended to this array- Throws:
NullPointerException- if the specified value is nullUnsupportedOperationException- if the set operation is not supported
-
addNull
void addNull()AppendsOracleJsonValue.NULLto the end of this array.- Throws:
UnsupportedOperationException- if the set operation is not supported
-
add
Appends the specified LocalDateTime to the end of this array. TheLocalDateTimeis appended to the array as an instance ofOracleJsonTimestamp.- Parameters:
value- the value to be appended to this array- Throws:
NullPointerException- if the specified value is nullUnsupportedOperationException- if the set operation is not supported
-
add
Appends the specified OffsetDateTime to the end of this array. TheOffsetDateTimeis appended to the array as an instance ofOracleJsonTimestampTZ.- Parameters:
value- the value to be appended to this array- Throws:
NullPointerException- if the specified value is nullUnsupportedOperationException- if the set operation is not supported
-
add
void add(byte[] value) Appends the specified byte array to the end of this array. The byte array is appended to the array as an instance ofOracleJsonBinary.- Parameters:
value- the value to be appended to this array- Throws:
NullPointerException- if the specified value is nullUnsupportedOperationException- if the set operation is not supported
-
getValuesAs
Returns a view of this array for the given element type.- Parameters:
c- a subtype of OracleJsonValue- Returns:
- the view of this array
-