Package oracle.sql.json
Interface OracleJsonObject
-
- All Superinterfaces:
Map<String,OracleJsonValue>
,OracleJsonStructure
,OracleJsonValue
public interface OracleJsonObject extends OracleJsonStructure, Map<String,OracleJsonValue>
A JSON object (an unordered collection of zero or more key/value pairs). The object may contain any subtype ofOracleJsonValue
which includes the extended SQL types such asOracleJsonTimestamp
.Instances of
Example:OracleJsonObject
may either be mutable or immutable. When an instance is immutable, calling methods that would mutate the object will throwUnsupportedOperationException
. For example,OracleJsonObject
instances that are returned from aResultSet
are immutable. Instances that are returned fromOracleJsonFactory.createObject()
andOracleJsonFactory.createObject(OracleJsonObject)
methods are mutable.import oracle.sql.json.OracleJsonFactory; import oracle.sql.json.OracleJsonObject; public class JsonObjectExample { public static void main(String[] args) { OracleJsonFactory factory = new OracleJsonFactory(); OracleJsonObject obj = factory.createObject(); obj.put("name", "orange"); obj.put("count", 12); System.out.println(obj.toString()); System.out.println(obj.getString("name")); } }
Running this example prints:
{"name":"orange","count":12} orange
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface java.util.Map
Map.Entry<K extends Object,V extends Object>
-
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 BigDecimal
getBigDecimal(String key)
Returns the decimal to which the specified key is mapped.BigDecimal
getBigDecimal(String key, BigDecimal defaultValue)
Returns the long to which the specified key is mapped.boolean
getBoolean(String key)
Returns the boolean to which the specified key is mapped.boolean
getBoolean(String key, boolean defaultValue)
Returns the boolean to which the specified key is mapped.byte[]
getBytes(String key)
Returns the binary value to which the specified key is mapped.byte[]
getBytes(String key, byte[] defaultValue)
Returns the binary value to which the specified key is mapped.double
getDouble(String key)
Returns the double to which the specified key is mapped.double
getDouble(String key, double defaultValue)
Returns the double to which the specified key is mapped.int
getInt(String key)
Returns the integer to which the specified key is mapped.int
getInt(String key, int defaultValue)
Returns the integer to which the specified key is mapped.java.time.LocalDateTime
getLocalDateTime(String key)
Returns the value to which the specified key is mapped.java.time.LocalDateTime
getLocalDateTime(String key, java.time.LocalDateTime defaultValue)
Returns the value to which the specified key is mapped.long
getLong(String key)
Returns the long to which the specified key is mapped.long
getLong(String key, long defaultValue)
Returns the long to which the specified key is mapped.java.time.OffsetDateTime
getOffsetDateTime(String key)
Returns the value to which the specified key is mapped.java.time.OffsetDateTime
getOffsetDateTime(String key, java.time.OffsetDateTime defaultValue)
Returns the value to which the specified key is mapped.String
getString(String key)
Returns the string to which the specified key is mapped.String
getString(String key, String defaultValue)
Returns the string to which the specified key is mapped.boolean
isNull(String key)
Returns true if the specified key is mapped to a value equal toOracleJsonValue.NULL
.OracleJsonValue
put(String key, boolean value)
Associates the specified boolean value with the specified key.OracleJsonValue
put(String key, byte[] values)
Associates the specified binary value with the specified key.OracleJsonValue
put(String key, double value)
Associates the specified double value with the specified key.OracleJsonValue
put(String key, int value)
Associates the specified integer value with the specified key.OracleJsonValue
put(String key, long value)
Associates the specified long value with the specified key.OracleJsonValue
put(String key, String value)
Associates the specified string value with the specified key.OracleJsonValue
put(String key, BigDecimal value)
Associates the specified decimal value with the specified key.OracleJsonValue
put(String key, java.time.LocalDateTime value)
Associates the specified value with the specified key.OracleJsonValue
put(String key, java.time.OffsetDateTime value)
Associates the specified value with the specified key.OracleJsonValue
putNull(String key)
Associates theOracleJsonValue.NULL
with the specified key.-
Methods inherited from interface java.util.Map
clear, compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, entrySet, equals, forEach, get, getOrDefault, hashCode, isEmpty, keySet, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, replaceAll, size, values
-
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(String key)
Returns the string to which the specified key is mapped. This is a convenience method that is equivalent toget(key).asJsonString().getString()
.- Parameters:
key
- the key whose associated value is to be returned- Returns:
- the value to which the specified key is mapped
- Throws:
ClassCastException
- if the value to which the specified key is mapped is not an instance of OracleJsonString.NullPointerException
- if the specified key does not have a mapping
-
getInt
int getInt(String key)
Returns the integer to which the specified key is mapped. This is a convenience method that is equivalent to((OracleJsonNumber)get(key)).intValue()
.- Parameters:
key
- the key whose associated value is to be returned- Returns:
- the value to which the specified key is mapped
- Throws:
ClassCastException
- if the value to which the specified key is mapped is not an instance of OracleJsonNumber.NullPointerException
- if the specified key does not have a mapping
-
getDouble
double getDouble(String key)
Returns the double to which the specified key is mapped. This is a convenience method that is equivalent to((OracleJsonNumber)get(key)).doubleValue()
.- Parameters:
key
- the key whose associated value is to be returned- Returns:
- the value to which the specified key is mapped
- Throws:
ClassCastException
- if the value to which the specified key is mapped is not an instance of OracleJsonNumber.NullPointerException
- if the specified key does not have a mapping
-
getLong
long getLong(String key)
Returns the long to which the specified key is mapped. This is a convenience method that is equivalent to((OracleJsonNumber)get(key)).longValue()
.- Parameters:
key
- the key whose associated value is to be returned- Returns:
- the value to which the specified key is mapped
- Throws:
ClassCastException
- if the value to which the specified key is mapped is not an instance of OracleJsonNumber.NullPointerException
- if the specified key does not have a mapping
-
getBigDecimal
BigDecimal getBigDecimal(String key)
Returns the decimal to which the specified key is mapped. This is a convenience method that is equivalent to((OracleJsonNumber)get(key)).bigDecimalValue()
.- Parameters:
key
- the key whose associated value is to be returned- Returns:
- the value to which the specified key is mapped
- Throws:
ClassCastException
- if the value to which the specified key is mapped is not an instance of OracleJsonNumber.NullPointerException
- if the specified key does not have a mapping
-
getBoolean
boolean getBoolean(String key)
Returns the boolean to which the specified key is mapped. Specifically, returnstrue
if the mapped value is equal toOracleJsonValue.TRUE
andfalse
if the value at the mapped value is equal toOracleJsonValue.FALSE
.- Parameters:
key
- the key whose associated value is to be returned- Returns:
- the value to which the specified key is mapped
- Throws:
ClassCastException
- if the value to which the specified key is mapped is not equal to OracleJsonValue.TRUE or OracleJsonValue.FALSENullPointerException
- if the specified key does not have a mapping
-
isNull
boolean isNull(String key)
Returns true if the specified key is mapped to a value equal toOracleJsonValue.NULL
.- Parameters:
key
- the key whose associated value is to be returned- Returns:
- the value to which the specified key is mapped
- Throws:
NullPointerException
- if the specified key does not have a mapping
-
getLocalDateTime
java.time.LocalDateTime getLocalDateTime(String key)
Returns the value to which the specified key is mapped. This is a convenience method that is equivalent toget(key).asJsonDate().getLocalDateTime()
orget(key).asJsonTimestamp().getLocalDateTime()
depending if the value is a date or a timestamp.- Parameters:
key
- the key whose associated value is to be returned- Returns:
- the value to which the specified key is mapped
- Throws:
ClassCastException
- if the value to which the specified key is mapped is not an instance of OracleJsonDate or OracleJsonTimestamp.NullPointerException
- if the specified key does not have a mapping
-
getOffsetDateTime
java.time.OffsetDateTime getOffsetDateTime(String key)
Returns the value to which the specified key is mapped. This is a convenience method that is equivalent toget(key).asJsonTimestampTZ().getOffsetDateTime()
.- Parameters:
key
- the key whose associated value is to be returned- Returns:
- the value to which the specified key is mapped
- Throws:
ClassCastException
- if the value to which the specified key is mapped is not an instance of OracleJsonTimestampTZ.NullPointerException
- if the specified key does not have a mapping
-
getBytes
byte[] getBytes(String key)
Returns the binary value to which the specified key is mapped. This is a convenience method that is equivalent toget(key).asJsonBinary().getBytes()
- Parameters:
key
- the key whose associated value is to be returned- Returns:
- the value to which the specified key is mapped
- Throws:
ClassCastException
- if the value to which the specified key is mapped is not an instance of OracleJsonBinary.NullPointerException
- if the specified key does not have a mapping
-
getString
String getString(String key, String defaultValue)
Returns the string to which the specified key is mapped. If an instance ofOracleJsonString
is mapped to the key, then the result of callinggetString()
on the instance is returned. Otherwise, the specifieddefaultValue
is returned.- Parameters:
key
- the key whose associated value is to be returneddefaultValue
- a default value to return- Returns:
- the value to which the specified key is mapped or the default value
-
getInt
int getInt(String key, int defaultValue)
Returns the integer to which the specified key is mapped. If an instance ofOracleJsonNumber
is mapped to the key, then the result of callingintValue()
the instance is returned. Otherwise, the specifieddefaultValue
is returned.- Parameters:
key
- the key whose associated value is to be returneddefaultValue
- a default value to return- Returns:
- the value to which the specified key is mapped or the default value
-
getDouble
double getDouble(String key, double defaultValue)
Returns the double to which the specified key is mapped. If an instance ofOracleJsonNumber
is mapped to the key, then the result of callingdoubleValue()
the instance is returned. Otherwise, the specifieddefaultValue
is returned.- Parameters:
key
- the key whose associated value is to be returneddefaultValue
- a default value to return- Returns:
- the value to which the specified key is mapped or the default value
-
getLong
long getLong(String key, long defaultValue)
Returns the long to which the specified key is mapped. If an instance ofOracleJsonNumber
is mapped to the key, then the result of callinglongValue()
the instance is returned. Otherwise, the specifieddefaultValue
is returned.- Parameters:
key
- the key whose associated value is to be returneddefaultValue
- a default value to return- Returns:
- the value to which the specified key is mapped or the default value
-
getBigDecimal
BigDecimal getBigDecimal(String key, BigDecimal defaultValue)
Returns the long to which the specified key is mapped. If an instance ofOracleJsonNumber
is mapped to the key, then the result of callingbigDecimalValue()
the instance is returned. Otherwise, the specifieddefaultValue
is returned.- Parameters:
key
- the key whose associated value is to be returneddefaultValue
- a default value to return- Returns:
- the value to which the specified key is mapped or the default value
-
getBoolean
boolean getBoolean(String key, boolean defaultValue)
Returns the boolean to which the specified key is mapped. If the mapped value is equal toOracleJsonValue.TRUE
thentrue
is returned. If the mapped value is equal toOracleJsonValue.FALSE
thenfalse
is returned. Otherwise, the specifieddefaultValue
is returned.- Parameters:
key
- the key whose associated value is to be returneddefaultValue
- a default value to return- Returns:
- the value to which the specified key is mapped or the default value
-
getLocalDateTime
java.time.LocalDateTime getLocalDateTime(String key, java.time.LocalDateTime defaultValue)
Returns the value to which the specified key is mapped. If the mapped value is a date or a timestamp, then the result of callinggetLocalDateTime()
on the value is returned. Otherwise, the specifieddefaultValue
is returned.- Parameters:
key
- the key whose associated value is to be returneddefaultValue
- a default value to return- Returns:
- the value to which the specified key is mapped or the default value
-
getOffsetDateTime
java.time.OffsetDateTime getOffsetDateTime(String key, java.time.OffsetDateTime defaultValue)
Returns the value to which the specified key is mapped. If the mapped value is an instance ofOracleTimestampTZ
, then the result of callinggetOffsetDateTime()
on the value is returned.- Parameters:
key
- the key whose associated value is to be returneddefaultValue
- a default value to return- Returns:
- the value to which the specified key is mapped or the default value
-
getBytes
byte[] getBytes(String key, byte[] defaultValue)
Returns the binary value to which the specified key is mapped. If an instance ofOracleJsonBinary
is mapped to the key, then the result of callinggetBytes()
on the instance is returned. Otherwise, the specifieddefaultValue
is returned.- Parameters:
key
- the key whose associated value is to be returneddefaultValue
- a default value to return- Returns:
- the value to which the specified key is mapped or the default value
-
put
OracleJsonValue put(String key, String value)
Associates the specified string value with the specified key. The string is added to the object as an instance ofOracleJsonString
. If the object previously contained a mapping for the key, the old value is replaced.- Parameters:
key
- the key with which the specified value is to be associatedvalue
- the value to be associated with the specified key- Returns:
- the previous value associated with the key, or null if there was no mapping for key.
- Throws:
UnsupportedOperationException
- if the put operation is not supported
-
put
OracleJsonValue put(String key, int value)
Associates the specified integer value with the specified key. The integer is added to the object as an instance ofOracleJsonDecimal
. If the object previously contained a mapping for the key, the old value is replaced.- Parameters:
key
- the key with which the specified value is to be associatedvalue
- the value to be associated with the specified key- Returns:
- the previous value associated with the key, or null if there was no mapping for key.
- Throws:
UnsupportedOperationException
- if the put operation is not supported
-
put
OracleJsonValue put(String key, long value)
Associates the specified long value with the specified key. The long is added to the object as an instance ofOracleJsonDecimal
. If the object previously contained a mapping for the key, the old value is replaced.- Parameters:
key
- the key with which the specified value is to be associatedvalue
- the value to be associated with the specified key- Returns:
- the previous value associated with the key, or null if there was no mapping for key.
- Throws:
UnsupportedOperationException
- if the put operation is not supported
-
put
OracleJsonValue put(String key, BigDecimal value) throws OracleJsonException
Associates the specified decimal value with the specified key. The decimal is added to the object as an instance ofOracleJsonDecimal
. If the object previously contained a mapping for the key, the old value is replaced.- Parameters:
key
- the key with which the specified value is to be associatedvalue
- the value to be associated with the specified key- Returns:
- the previous value associated with the key, or null if there was no mapping for key.
- Throws:
UnsupportedOperationException
- if the put operation is not supportedOracleJsonException
-
put
OracleJsonValue put(String key, double value)
Associates the specified double value with the specified key. The double is added to the object as an instance ofOracleJsonDouble
. If the object previously contained a mapping for the key, the old value is replaced.- Parameters:
key
- the key with which the specified value is to be associatedvalue
- the value to be associated with the specified key- Returns:
- the previous value associated with the key, or null if there was no mapping for key.
- Throws:
UnsupportedOperationException
- if the put operation is not supported
-
put
OracleJsonValue put(String key, boolean value)
Associates the specified boolean value with the specified key. If the value istrue
,OracleJsonValue.TRUE
is associated with the key and if it isfalse
thenOracleJsonValue.FALSE
is associated with the key. If the object previously contained a mapping for the key, the old value is replaced.- Parameters:
key
- the key with which the specified value is to be associatedvalue
- the value to be associated with the specified key- Returns:
- the previous value associated with the key, or null if there was no mapping for key.
- Throws:
UnsupportedOperationException
- if the put operation is not supported
-
putNull
OracleJsonValue putNull(String key)
Associates theOracleJsonValue.NULL
with the specified key. If the object previously contained a mapping for the key, the old value is replaced.- Parameters:
key
- the key with which theOracleJsonValue.NULL
value is to be associated- Returns:
- the previous value associated with the key, or null if there was no mapping for key.
- Throws:
UnsupportedOperationException
- if the put operation is not supported
-
put
OracleJsonValue put(String key, java.time.LocalDateTime value)
Associates the specified value with the specified key. The value is added to the object as an instance ofOracleJsonTimestamp
. If the object previously contained a mapping for the key, the old value is replaced.- Parameters:
key
- the key with which the specified value is to be associatedvalue
- the value to be associated with the specified key- Returns:
- the previous value associated with the key, or null if there was no mapping for key.
- Throws:
UnsupportedOperationException
- if the put operation is not supported
-
put
OracleJsonValue put(String key, java.time.OffsetDateTime value)
Associates the specified value with the specified key. The value is added to the object as an instance ofOracleJsonTimestampTZ
. If the object previously contained a mapping for the key, the old value is replaced.- Parameters:
key
- the key with which the specified value is to be associatedvalue
- the value to be associated with the specified key- Returns:
- the previous value associated with the key, or null if there was no mapping for key.
- Throws:
UnsupportedOperationException
- if the put operation is not supported
-
put
OracleJsonValue put(String key, byte[] values)
Associates the specified binary value with the specified key. The binary value is added to the object as an instance ofOracleJsonBinary
. If the object previously contained a mapping for the key, the old value is replaced.- Parameters:
key
- the key with which the specified value is to be associatedvalue
- the value to be associated with the specified key- Returns:
- the previous value associated with the key, or null if there was no mapping for key.
- Throws:
UnsupportedOperationException
- if the put operation is not supported
-
-