public interface OracleJsonObject extends OracleJsonStructure, Map<String,OracleJsonValue>
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
OracleJsonValue.OracleJsonType
FALSE, NULL, TRUE
Modifier and Type | Method and 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 to
OracleJsonValue.NULL . |
OracleJsonValue |
put(String key,
BigDecimal value)
Associates the specified decimal value with the specified key.
|
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,
java.time.LocalDateTime value)
Associates the specified value with the specified key.
|
OracleJsonValue |
put(String key,
long value)
Associates the specified long value with the specified key.
|
OracleJsonValue |
put(String key,
java.time.OffsetDateTime value)
Associates the specified value with the specified key.
|
OracleJsonValue |
put(String key,
String value)
Associates the specified string value with the specified key.
|
OracleJsonValue |
putNull(String key)
Associates the
OracleJsonValue.NULL with the specified key. |
asJsonArray, asJsonBinary, asJsonDate, asJsonDecimal, asJsonDouble, asJsonFloat, asJsonIntervalDS, asJsonIntervalYM, asJsonNumber, asJsonObject, asJsonString, asJsonTimestamp, asJsonTimestampTZ, getOracleJsonType, toString, wrap
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
String getString(String key)
get(key).asJsonString().getString()
.key
- the key whose associated value is to be returnedClassCastException
- 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 mappingint getInt(String key)
((OracleJsonNumber)get(key)).intValue()
.key
- the key whose associated value is to be returnedClassCastException
- 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 mappingdouble getDouble(String key)
((OracleJsonNumber)get(key)).doubleValue()
.key
- the key whose associated value is to be returnedClassCastException
- 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 mappinglong getLong(String key)
((OracleJsonNumber)get(key)).longValue()
.key
- the key whose associated value is to be returnedClassCastException
- 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 mappingBigDecimal getBigDecimal(String key)
((OracleJsonNumber)get(key)).bigDecimalValue()
.key
- the key whose associated value is to be returnedClassCastException
- 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 mappingboolean getBoolean(String key)
true
if the mapped value is equal to
OracleJsonValue.TRUE
and false
if the value at the mapped
value is equal to OracleJsonValue.FALSE
.key
- the key whose associated value is to be returnedClassCastException
- 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 mappingboolean isNull(String key)
OracleJsonValue.NULL
.key
- the key whose associated value is to be returnedNullPointerException
- if the specified key does not have a mappingjava.time.LocalDateTime getLocalDateTime(String key)
get(key).asJsonDate().getLocalDateTime()
or
get(key).asJsonTimestamp().getLocalDateTime()
depending if the value is a date or a timestamp.key
- the key whose associated value is to be returnedClassCastException
- 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 mappingjava.time.OffsetDateTime getOffsetDateTime(String key)
get(key).asJsonTimestampTZ().getOffsetDateTime()
.key
- the key whose associated value is to be returnedClassCastException
- 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 mappingbyte[] getBytes(String key)
get(key).asJsonBinary().getBytes()
key
- the key whose associated value is to be returnedClassCastException
- 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 mappingString getString(String key, String defaultValue)
OracleJsonString
is mapped to the key, then the result of calling
getString()
on the instance is returned.
Otherwise, the specified defaultValue
is returned.key
- the key whose associated value is to be returneddefaultValue
- a default value to returnint getInt(String key, int defaultValue)
OracleJsonNumber
is mapped to the key, then the result of calling
intValue()
the instance is returned.
Otherwise, the specified defaultValue
is returned.key
- the key whose associated value is to be returneddefaultValue
- a default value to returndouble getDouble(String key, double defaultValue)
OracleJsonNumber
is mapped to the key, then the result of calling
doubleValue()
the instance is
returned. Otherwise, the specified defaultValue
is returned.key
- the key whose associated value is to be returneddefaultValue
- a default value to returnlong getLong(String key, long defaultValue)
OracleJsonNumber
is mapped to the key, then the result of calling
longValue()
the instance is
returned. Otherwise, the specified defaultValue
is returned.key
- the key whose associated value is to be returneddefaultValue
- a default value to returnBigDecimal getBigDecimal(String key, BigDecimal defaultValue)
OracleJsonNumber
is mapped to the key, then the result of calling
bigDecimalValue()
the instance is
returned. Otherwise, the specified defaultValue
is returned.key
- the key whose associated value is to be returneddefaultValue
- a default value to returnboolean getBoolean(String key, boolean defaultValue)
OracleJsonValue.TRUE
then true
is
returned. If the mapped value is equal to OracleJsonValue.FALSE
then false
is returned. Otherwise, the specified
defaultValue
is returned.key
- the key whose associated value is to be returneddefaultValue
- a default value to returnjava.time.LocalDateTime getLocalDateTime(String key, java.time.LocalDateTime defaultValue)
getLocalDateTime()
on the value is returned. Otherwise, the
specified defaultValue
is returned.key
- the key whose associated value is to be returneddefaultValue
- a default value to returnjava.time.OffsetDateTime getOffsetDateTime(String key, java.time.OffsetDateTime defaultValue)
OracleTimestampTZ
, then the result of
calling getOffsetDateTime()
on the value is returned.key
- the key whose associated value is to be returneddefaultValue
- a default value to returnbyte[] getBytes(String key, byte[] defaultValue)
OracleJsonBinary
is mapped to the key, then the result of calling
getBytes()
on the instance is returned.
Otherwise, the specified defaultValue
is returned.key
- the key whose associated value is to be returneddefaultValue
- a default value to returnOracleJsonValue put(String key, String value)
OracleJsonString
. If the
object previously contained a mapping for the key, the old value is
replaced.key
- the key with which the specified value is to be associatedvalue
- the value to be associated with the specified keyUnsupportedOperationException
- if the put operation is not supportedOracleJsonValue put(String key, int value)
OracleJsonDecimal
. If the
object previously contained a mapping for the key, the old value is
replaced.key
- the key with which the specified value is to be associatedvalue
- the value to be associated with the specified keyUnsupportedOperationException
- if the put operation is not supportedOracleJsonValue put(String key, long value)
OracleJsonDecimal
. If the
object previously contained a mapping for the key, the old value is
replaced.key
- the key with which the specified value is to be associatedvalue
- the value to be associated with the specified keyUnsupportedOperationException
- if the put operation is not supportedOracleJsonValue put(String key, BigDecimal value) throws OracleJsonException
OracleJsonDecimal
. If the
object previously contained a mapping for the key, the old value is
replaced.key
- the key with which the specified value is to be associatedvalue
- the value to be associated with the specified keyUnsupportedOperationException
- if the put operation is not supportedOracleJsonException
OracleJsonValue put(String key, double value)
OracleJsonDouble
. If the
object previously contained a mapping for the key, the old value is
replaced.key
- the key with which the specified value is to be associatedvalue
- the value to be associated with the specified keyUnsupportedOperationException
- if the put operation is not supportedOracleJsonValue put(String key, boolean value)
true
, OracleJsonValue.TRUE
is associated
with the key and if it is false
then OracleJsonValue.FALSE
is
associated with the key. If the object previously contained a mapping for the key,
the old value is replaced.key
- the key with which the specified value is to be associatedvalue
- the value to be associated with the specified keyUnsupportedOperationException
- if the put operation is not supportedOracleJsonValue putNull(String key)
OracleJsonValue.NULL
with the specified key. If the
object previously contained a mapping for the key, the old value is
replaced.key
- the key with which the OracleJsonValue.NULL
value is to
be associatedUnsupportedOperationException
- if the put operation is not supportedOracleJsonValue put(String key, java.time.LocalDateTime value)
OracleJsonTimestamp
. If
the object previously contained a mapping for the key, the old value is
replaced.key
- the key with which the specified value is to be associatedvalue
- the value to be associated with the specified keyUnsupportedOperationException
- if the put operation is not supportedOracleJsonValue put(String key, java.time.OffsetDateTime value)
OracleJsonTimestampTZ
. If
the object previously contained a mapping for the key, the old value is
replaced.key
- the key with which the specified value is to be associatedvalue
- the value to be associated with the specified keyUnsupportedOperationException
- if the put operation is not supportedOracleJsonValue put(String key, byte[] values)
OracleJsonBinary
. If
the object previously contained a mapping for the key, the old value is
replaced.key
- the key with which the specified value is to be associatedvalue
- the value to be associated with the specified keyUnsupportedOperationException
- if the put operation is not supported