Package oracle.sql.json
Interface OracleJsonObject
- All Superinterfaces:
Map<String,,OracleJsonValue> OracleJsonStructure,OracleJsonValue
A JSON object (an unordered collection of zero or more key/value
pairs). The object may contain any subtype of
OracleJsonValue
which includes the extended SQL types such as OracleJsonTimestamp.
Instances of OracleJsonObject may either be mutable or immutable. When
an instance is immutable, calling methods that would mutate the object will
throw UnsupportedOperationException. For example,
OracleJsonObject instances that are returned from a
ResultSet are immutable.
Instances that are returned from OracleJsonFactory.createObject() and
OracleJsonFactory.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
Modifier and TypeMethodDescriptiondefault OracleJsonArrayReturns the value to which the specified key is mapped.getBigDecimal(String key) Returns the decimal to which the specified key is mapped.getBigDecimal(String key, BigDecimal defaultValue) Returns the long to which the specified key is mapped.booleangetBoolean(String key) Returns the boolean to which the specified key is mapped.booleangetBoolean(String key, boolean defaultValue) Returns the boolean to which the specified key is mapped.byte[]Returns the binary value to which the specified key is mapped.byte[]Returns the binary value to which the specified key is mapped.doubleReturns the double to which the specified key is mapped.doubleReturns the double to which the specified key is mapped.intReturns the integer to which the specified key is mapped.intReturns the integer to which the specified key is mapped.getLocalDateTime(String key) Returns the value to which the specified key is mapped.getLocalDateTime(String key, LocalDateTime defaultValue) Returns the value to which the specified key is mapped.longReturns the long to which the specified key is mapped.longReturns the long to which the specified key is mapped.default OracleJsonObjectReturns the value to which the specified key is mapped.getOffsetDateTime(String key) Returns the value to which the specified key is mapped.getOffsetDateTime(String key, OffsetDateTime defaultValue) Returns the value to which the specified key is mapped.Returns the string to which the specified key is mapped.Returns the string to which the specified key is mapped.booleanReturns true if the specified key is mapped to a value equal toOracleJsonValue.NULL.Associates the specified boolean value with the specified key.Associates the specified binary value with the specified key.Associates the specified double value with the specified key.Associates the specified integer value with the specified key.Associates the specified long value with the specified key.Associates the specified string value with the specified key.put(String key, BigDecimal value) Associates the specified decimal value with the specified key.put(String key, LocalDateTime value) Associates the specified value with the specified key.put(String key, OffsetDateTime value) Associates the specified value with the specified key.Associates theOracleJsonValue.NULLwith 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, valuesMethods 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 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
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
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
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
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
Returns the boolean to which the specified key is mapped. Specifically, returnstrueif the mapped value is equal toOracleJsonValue.TRUEandfalseif 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
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
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
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
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
-
getObject
Returns the value to which the specified key is mapped. This is a convenience method that is equivalent toget(key).asJsonObject()- 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 OracleJsonObject.NullPointerException- if the specified key does not have a mapping
-
getArray
Returns the value to which the specified key is mapped. This is a convenience method that is equivalent toget(key).asJsonArray()- 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 OracleJsonArray.NullPointerException- if the specified key does not have a mapping
-
getString
Returns the string to which the specified key is mapped. If an instance ofOracleJsonStringis mapped to the key, then the result of callinggetString()on the instance is returned. Otherwise, the specifieddefaultValueis 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
Returns the integer to which the specified key is mapped. If an instance ofOracleJsonNumberis mapped to the key, then the result of callingintValue()the instance is returned. Otherwise, the specifieddefaultValueis 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
Returns the double to which the specified key is mapped. If an instance ofOracleJsonNumberis mapped to the key, then the result of callingdoubleValue()the instance is returned. Otherwise, the specifieddefaultValueis 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
Returns the long to which the specified key is mapped. If an instance ofOracleJsonNumberis mapped to the key, then the result of callinglongValue()the instance is returned. Otherwise, the specifieddefaultValueis 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
Returns the long to which the specified key is mapped. If an instance ofOracleJsonNumberis mapped to the key, then the result of callingbigDecimalValue()the instance is returned. Otherwise, the specifieddefaultValueis 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
Returns the boolean to which the specified key is mapped. If the mapped value is equal toOracleJsonValue.TRUEthentrueis returned. If the mapped value is equal toOracleJsonValue.FALSEthenfalseis returned. Otherwise, the specifieddefaultValueis 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
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 specifieddefaultValueis 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
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
Returns the binary value to which the specified key is mapped. If an instance ofOracleJsonBinaryis mapped to the key, then the result of callinggetBytes()on the instance is returned. Otherwise, the specifieddefaultValueis 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
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
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
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
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
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
Associates the specified boolean value with the specified key. If the value istrue,OracleJsonValue.TRUEis associated with the key and if it isfalsethenOracleJsonValue.FALSEis 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
Associates theOracleJsonValue.NULLwith 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.NULLvalue 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
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
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
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
-