Package oracle.sql.json
Interface OracleJsonArray
-
- All Superinterfaces:
Collection<OracleJsonValue>,Iterable<OracleJsonValue>,List<OracleJsonValue>,OracleJsonStructure,OracleJsonValue
public interface OracleJsonArray extends OracleJsonStructure, List<OracleJsonValue>
A JSON array (an ordered sequence of zero or more values). The object may contain any subtype ofOracleJsonValuewhich includes the extended SQL types such asOracleJsonTimestamp.Instances of
Example:OracleJsonArraymay either be mutable or immutable. When an instance is immutable, calling methods that would mutate the array will throwUnsupportedOperationException. For example,OracleJsonArrayinstances that are returned from aResultSetare immutable. Instances that are returned fromOracleJsonFactory.createArray()andOracleJsonFactory.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
-
<section role="region">
-
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
All Methods Instance Methods Abstract Methods Modifier and Type Method Description voidadd(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.voidadd(String value)Appends the specified string to the end of this array.voidadd(BigDecimal value)Appends the specified decimal to the end of this array.voidadd(java.time.Instant value)Appends the specified instant to the end of this array.voidaddNull()AppendsOracleJsonValue.NULLto the end of this array.BigDecimalgetBigDecimal(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.java.time.InstantgetInstant(int index)Returns the timestamp or date value at the specified position in the JSON array.intgetInt(int index)Returns the int at the specified position in the JSON array.longgetLong(int index)Returns the long at the specified position in the JSON array.StringgetString(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.OracleJsonValueset(int index, boolean value)Replaces the value at the specified position in the array with the specifiedboolean.OracleJsonValueset(int index, byte[] value)Replaces the value at the specified position in the array with the specified byte array.OracleJsonValueset(int index, double value)Replaces the value at the specified position in the array with the specifieddouble.OracleJsonValueset(int index, int value)Replaces the value at the specified position in the array with the specified integer.OracleJsonValueset(int index, long value)Replaces the value at the specified position in the array with the specifiedlong.OracleJsonValueset(int index, String value)Replaces the value at the specified position in the array with the specified string.OracleJsonValueset(int index, BigDecimal value)Replaces the value at the specified position in the array with the specified decimal value.OracleJsonValueset(int index, java.time.Instant value)Replaces the value at the specified position in the array with the specifiedInstant.OracleJsonValuesetNull(int index)Replaces the value at the specified position in the array withOracleJsonValue.NULL.-
Methods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArray
-
Methods 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, toArray
-
Methods inherited from interface oracle.sql.json.OracleJsonValue
asJsonArray, asJsonBinary, asJsonDate, asJsonDecimal, asJsonDouble, asJsonFloat, asJsonIntervalDS, asJsonIntervalYM, asJsonNumber, asJsonObject, asJsonString, asJsonTimestamp, getOracleJsonType, toString, wrap
-
-
-
<section role="region">
-
Method Detail
-
getString
String getString(int index)
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
BigDecimal getBigDecimal(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)).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
-
getInstant
java.time.Instant getInstant(int index)
Returns the timestamp or date value at the specified position in the JSON array. When the value is a date, this method is equivalent toget(index).asJsonDate().getInstant(). Similarly, when the value is a timestamp, this method is equivalent toget(index).asJsonTimestamp().getInstant().- 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.
-
set
OracleJsonValue set(int index, String value)
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
OracleJsonValue set(int index, int value)
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
OracleJsonValue set(int index, double value)
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
OracleJsonValue set(int index, long value)
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
OracleJsonValue set(int index, BigDecimal value) throws OracleJsonException
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
OracleJsonValue set(int index, boolean value)
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
OracleJsonValue setNull(int index)
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
OracleJsonValue set(int index, java.time.Instant value)
Replaces the value at the specified position in the array with the specifiedInstant. TheInstantis 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
OracleJsonValue set(int index, byte[] value)
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
void add(String value)
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
void add(BigDecimal value)
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
void add(java.time.Instant value)
Appends the specified instant to the end of this array. TheInstantis 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
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
<T extends OracleJsonValue> List<T> getValuesAs(Class<T> c)
Returns a view of this array for the given element type.- Parameters:
c- a subtype of OracleJsonValue- Returns:
- the view of this array
-
-