Interface OracleJsonValue
-
- All Known Subinterfaces:
OracleJsonArray
,OracleJsonBinary
,OracleJsonDate
,OracleJsonDecimal
,OracleJsonDouble
,OracleJsonFloat
,OracleJsonIntervalDS
,OracleJsonIntervalYM
,OracleJsonNumber
,OracleJsonObject
,OracleJsonString
,OracleJsonStructure
,OracleJsonTimestamp
,OracleJsonTimestampTZ
public interface OracleJsonValue
The interface for JSON type in Oracle Database. This is the super type of all JSON type values:
Example:OracleJsonObject
,OracleJsonArray
,OracleJsonString
,OracleJsonDecimal
,OracleJsonFloat
,OracleJsonDouble
,OracleJsonTimestamp
,OracleJsonTimestampTZ
,OracleJsonDate
,OracleJsonBinary
,OracleJsonIntervalDS
,OracleJsonIntervalYM
,OracleJsonValue.TRUE
,OracleJsonValue.FALSE
, andOracleJsonValue.NULL
. Use the methodgetOracleJsonType()
to determine the specific type of a value.import oracle.sql.json.OracleJsonArray; import oracle.sql.json.OracleJsonDouble; import oracle.sql.json.OracleJsonFactory; import oracle.sql.json.OracleJsonObject; import oracle.sql.json.OracleJsonString; import oracle.sql.json.OracleJsonValue; import oracle.sql.json.OracleJsonValue.OracleJsonType; public class JsonValueExample { public static void main(String[] args) { OracleJsonFactory factory = new OracleJsonFactory(); OracleJsonArray arr = factory.createArray(); arr.add(factory.createString("foo")); arr.add(factory.createDouble(123.456d)); OracleJsonObject obj = factory.createObject(); obj.put("hello", "world"); arr.add(obj); arr.add(OracleJsonValue.NULL); arr.add(OracleJsonValue.TRUE); System.out.println(arr.toString()); for (OracleJsonValue value : arr) { OracleJsonType kind = value.getOracleJsonType(); System.out.println(kind); switch (kind) { case DOUBLE: OracleJsonDouble jsonDouble = value.asJsonDouble(); System.out.println(" - " + jsonDouble.doubleValue()); break; case STRING: OracleJsonString jsonString = value.asJsonString(); System.out.println(" - " + jsonString.getString()); break; case OBJECT: OracleJsonObject jsonObject = value.asJsonObject(); System.out.println(" - " + jsonObject.toString()); break; case TRUE: case NULL: break; // do nothing default: throw new IllegalStateException("Unexpected"); } } } }
Running this example prints:
["foo",123.456,{"hello":"world"},null,true] STRING - foo DOUBLE - 123.456 OBJECT - {"hello":"world"} NULL TRUE
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static class
OracleJsonValue.OracleJsonType
-
Field Summary
Fields Modifier and Type Field Description static OracleJsonValue
FALSE
JSON false.static OracleJsonValue
NULL
JSON null.static OracleJsonValue
TRUE
JSON true.
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default OracleJsonArray
asJsonArray()
Returns this value asOracleJsonArray
.default OracleJsonBinary
asJsonBinary()
Returns this value asOracleJsonBinary
.default OracleJsonDate
asJsonDate()
Returns this value asOracleJsonDate
.default OracleJsonDecimal
asJsonDecimal()
Returns this value asOracleJsonDecimal
.default OracleJsonDouble
asJsonDouble()
Returns this value asOracleJsonDouble
.default OracleJsonFloat
asJsonFloat()
Returns this value asOracleJsonFloat
.default OracleJsonIntervalDS
asJsonIntervalDS()
Returns this value asOracleJsonIntervalDS
.default OracleJsonIntervalYM
asJsonIntervalYM()
Returns this value asOracleJsonIntervalYM
.default OracleJsonNumber
asJsonNumber()
Returns this value asOracleJsonNumber
.default OracleJsonObject
asJsonObject()
Returns this value asOracleJsonObject
.default OracleJsonString
asJsonString()
Returns this value asOracleJsonString
.default OracleJsonTimestamp
asJsonTimestamp()
Returns this value asOracleJsonTimestamp
.default OracleJsonTimestampTZ
asJsonTimestampTZ()
Returns this value asOracleJsonTimestampTZ
.OracleJsonValue.OracleJsonType
getOracleJsonType()
Returns the type of this JSON value.String
toString()
Returns the JSON text for this value.<T> T
wrap(Class<T> wrapper)
Returns a JSON-P (javax.json) wrapper around this value.
-
-
-
Field Detail
-
NULL
static final OracleJsonValue NULL
JSON null.
-
TRUE
static final OracleJsonValue TRUE
JSON true.
-
FALSE
static final OracleJsonValue FALSE
JSON false.
-
-
Method Detail
-
getOracleJsonType
OracleJsonValue.OracleJsonType getOracleJsonType()
Returns the type of this JSON value.- Returns:
- the value type
-
toString
String toString()
Returns the JSON text for this value.
-
wrap
<T> T wrap(Class<T> wrapper)
Returns a JSON-P (javax.json) wrapper around this value. For example:import javax.json.JsonObject; ... OracleJsonObject oraObject = ...; JsonObject jsonObject = oraObject.wrap(JsonObject.class);
The returned object is a logical view of the underlying value. Any changes to the value will be observed by the returned wrapper object. All instances of
javax.json.JsonValue
produced by JDBC implement thejava.sql.Wrapper
interface which can be used to map back to an instance oforacle.sql.json.OracleJsonValue
. For example:import javax.json.JsonObject; import java.sql.Wrapper ... JsonObject jsonObject = ...; OracleJsonObject oraObject = ((Wrapper)jsonObject).unwrap(OracleJsonObject.class);
The following table summarizes the object-model mappings between
oracle.sql.json.OracleJsonValue
andjavax.json.JsonValue
.oracle.sql.json javax.json oracle.sql.json.OracleJsonObject
javax.json.JsonObject
oracle.sql.json.OracleJsonArray
javax.json.JsonArray
oracle.sql.json.OracleJsonString
oracle.sql.json.OracleJsonTimestamp
oracle.sql.json.OracleJsonDate
oracle.sql.json.OracleJsonBinary
oracle.sql.json.OracleJsonIntervalDS
oracle.sql.json.OracleJsonIntervalYM
javax.json.JsonString
oracle.sql.json.OracleJsonDecimal
oracle.sql.json.OracleJsonDouble
oracle.sql.json.OracleJsonFloat
javax.json.JsonNumber
oracle.sql.json.OracleJsonValue.TRUE
javax.json.JsonValue.TRUE
oracle.sql.json.OracleJsonValue.FALSE
javax.json.JsonValue.FALSE
oracle.sql.json.OracleJsonValue.NULL
javax.json.JsonValue.NULL
- Parameters:
wrapper
- the interface to view this object as. Must be assignable tojavax.json.JsonValue
-
asJsonObject
default OracleJsonObject asJsonObject()
Returns this value asOracleJsonObject
. This method is equivalent to(OracleJsonObject)this
.- Returns:
- the OracleJsonObject
- Throws:
ClassCastException
- if this value is not an instance ofOracleJsonObject
.
-
asJsonArray
default OracleJsonArray asJsonArray()
Returns this value asOracleJsonArray
. This method is equivalent to(OracleJsonArray)this
.- Returns:
- the OracleJsonArray
- Throws:
ClassCastException
- if this value is not an instance ofOracleJsonArray
.
-
asJsonString
default OracleJsonString asJsonString()
Returns this value asOracleJsonString
. This method is equivalent to(OracleJsonString)this
.- Returns:
- the OracleJsonString
- Throws:
ClassCastException
- if this value is not an instance ofOracleJsonString
.
-
asJsonDecimal
default OracleJsonDecimal asJsonDecimal()
Returns this value asOracleJsonDecimal
. This method is equivalent to(OracleJsonDecimal)this
.- Returns:
- the OracleJsonDecimal
- Throws:
ClassCastException
- if this value is not an instance ofOracleJsonDecimal
.
-
asJsonDouble
default OracleJsonDouble asJsonDouble()
Returns this value asOracleJsonDouble
. This method is equivalent to(OracleJsonDouble)this
.- Returns:
- the OracleJsonDouble
- Throws:
ClassCastException
- if this value is not an instance ofOracleJsonDouble
.
-
asJsonFloat
default OracleJsonFloat asJsonFloat()
Returns this value asOracleJsonFloat
. This method is equivalent to(OracleJsonFloat)this
.- Returns:
- the OracleJsonFloat
- Throws:
ClassCastException
- if this value is not an instance ofOracleJsonFloat
.
-
asJsonNumber
default OracleJsonNumber asJsonNumber()
Returns this value asOracleJsonNumber
. This method is equivalent to(OracleJsonNumber)this
.- Returns:
- the OracleJsonNumber
- Throws:
ClassCastException
- if this value is not an instance ofOracleJsonNumber
.
-
asJsonIntervalDS
default OracleJsonIntervalDS asJsonIntervalDS()
Returns this value asOracleJsonIntervalDS
. This method is equivalent to(OracleJsonIntervalDS)this
.- Returns:
- the OracleJsonIntervalDS
- Throws:
ClassCastException
- if this value is not an instance ofOracleJsonIntervalDS
.
-
asJsonIntervalYM
default OracleJsonIntervalYM asJsonIntervalYM()
Returns this value asOracleJsonIntervalYM
. This method is equivalent to(OracleJsonIntervalYM)this
.- Returns:
- the OracleJsonIntervalYM
- Throws:
ClassCastException
- if this value is not an instance ofOracleJsonIntervalYM
.
-
asJsonTimestamp
default OracleJsonTimestamp asJsonTimestamp()
Returns this value asOracleJsonTimestamp
. This method is equivalent to(OracleJsonTimestamp)this
.- Returns:
- the OracleJsonTimestamp
- Throws:
ClassCastException
- if this value is not an instance ofOracleJsonTimestamp
.
-
asJsonTimestampTZ
default OracleJsonTimestampTZ asJsonTimestampTZ()
Returns this value asOracleJsonTimestampTZ
. This method is equivalent to(OracleJsonTimestampTZ)this
.- Returns:
- the OracleJsonTimestampTZ
- Throws:
ClassCastException
- if this value is not an instance ofOracleJsonTimestampTZ
.
-
asJsonDate
default OracleJsonDate asJsonDate()
Returns this value asOracleJsonDate
. This method is equivalent to(OracleJsonDate)this
.- Returns:
- the OracleJsonDate
- Throws:
ClassCastException
- if this value is not an instance ofOracleJsonDate
.
-
asJsonBinary
default OracleJsonBinary asJsonBinary()
Returns this value asOracleJsonBinary
. This method is equivalent to(OracleJsonBinary)this
.- Returns:
- the OracleJsonBinary
- Throws:
ClassCastException
- if this value is not an instance ofOracleJsonBinary
.
-
-