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 ofOracleJsonValue
which includes the extended SQL types such asOracleJsonTimestamp
.Instances of
Example:OracleJsonArray
may either be mutable or immutable. When an instance is immutable, calling methods that would mutate the array will throwUnsupportedOperationException
. For example,OracleJsonArray
instances that are returned from aResultSet
are 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
-
-
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 void
add(boolean value)
Appends the specifiedboolean
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 specifieddouble
to the end of this array.void
add(int value)
Appends the specifiedinteger
to the end of this array.void
add(long value)
Appends the specifiedlong
to the end of this array.void
add(String value)
Appends the specified string to the end of this array.void
add(BigDecimal value)
Appends the specified decimal to the end of this array.void
add(java.time.LocalDateTime value)
Appends the specified LocalDateTime to the end of this array.void
add(java.time.OffsetDateTime value)
Appends the specified OffsetDateTime to the end of this array.void
addNull()
AppendsOracleJsonValue.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>
List<T>getValuesAs(Class<T> c)
Returns a view of this array for the given element type.boolean
isNull(int index)
Returnstrue
if the value at the specified position in the array is equal toJsonValue.NULL
.OracleJsonValue
set(int index, boolean value)
Replaces the value at the specified position in the array with the specifiedboolean
.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 specifieddouble
.OracleJsonValue
set(int index, int value)
Replaces the value at the specified position in the array with the specified integer.OracleJsonValue
set(int index, long value)
Replaces the value at the specified position in the array with the specifiedlong
.OracleJsonValue
set(int index, String value)
Replaces the value at the specified position in the array with the specified string.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, java.time.LocalDateTime value)
Replaces the value at the specified position in the array with the specifiedLocalDateTime
.OracleJsonValue
set(int index, java.time.OffsetDateTime value)
Replaces the value at the specified position in the array with the specifiedOffsetDateTime
.OracleJsonValue
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, 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, asJsonTimestampTZ, getOracleJsonType, toString, wrap
-
-
-
-
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, returnstrue
if the value at the specified position is equal toOracleJsonValue.TRUE
andfalse
if 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.TRUE
orOracleJson.FALSE
.
-
isNull
boolean isNull(int index)
Returnstrue
if 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
java.time.LocalDateTime getLocalDateTime(int index)
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
java.time.OffsetDateTime getOffsetDateTime(int index)
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.
-
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 newint
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 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 newdouble
is 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 newlong
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 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.TRUE
is 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.LocalDateTime value)
Replaces the value at the specified position in the array with the specifiedLocalDateTime
. TheLocalDateTime
is 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, java.time.OffsetDateTime value)
Replaces the value at the specified position in the array with the specifiedOffsetDateTime
. TheOffsetDateTime
is 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
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 specifiedinteger
to the end of this array. Theint
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(double value)
Appends the specifieddouble
to the end of this array. Thedouble
is 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 specifiedlong
to the end of this array. Thelong
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(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 specifiedboolean
to the end of this array. If the specified value is true thenOracleJsonValue.TRUE
is 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.NULL
to the end of this array.- Throws:
UnsupportedOperationException
- if the set operation is not supported
-
add
void add(java.time.LocalDateTime value)
Appends the specified LocalDateTime to the end of this array. TheLocalDateTime
is 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(java.time.OffsetDateTime value)
Appends the specified OffsetDateTime to the end of this array. TheOffsetDateTime
is 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
<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
-
-