public interface OracleJsonValue
The interface for JSON type in Oracle Database. This is the super
type of all JSON type values:
OracleJsonObject
, OracleJsonArray
, OracleJsonString
,
OracleJsonDecimal
, OracleJsonFloat
, OracleJsonDouble
,
OracleJsonTimestamp
, OracleJsonTimestampTZ
, OracleJsonDate
, OracleJsonBinary
,
OracleJsonIntervalDS
, OracleJsonIntervalYM
,
OracleJsonValue.TRUE
,
OracleJsonValue.FALSE
, and
OracleJsonValue.NULL
. Use the method
getOracleJsonType()
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
Modifier and Type | Interface and Description |
---|---|
static class |
OracleJsonValue.OracleJsonType |
Modifier and Type | Field and Description |
---|---|
static OracleJsonValue |
FALSE
JSON false.
|
static OracleJsonValue |
NULL
JSON null.
|
static OracleJsonValue |
TRUE
JSON true.
|
Modifier and Type | Method and Description |
---|---|
default OracleJsonArray |
asJsonArray()
Returns this value as
OracleJsonArray . |
default OracleJsonBinary |
asJsonBinary()
Returns this value as
OracleJsonBinary . |
default OracleJsonDate |
asJsonDate()
Returns this value as
OracleJsonDate . |
default OracleJsonDecimal |
asJsonDecimal()
Returns this value as
OracleJsonDecimal . |
default OracleJsonDouble |
asJsonDouble()
Returns this value as
OracleJsonDouble . |
default OracleJsonFloat |
asJsonFloat()
Returns this value as
OracleJsonFloat . |
default OracleJsonIntervalDS |
asJsonIntervalDS()
Returns this value as
OracleJsonIntervalDS . |
default OracleJsonIntervalYM |
asJsonIntervalYM()
Returns this value as
OracleJsonIntervalYM . |
default OracleJsonNumber |
asJsonNumber()
Returns this value as
OracleJsonNumber . |
default OracleJsonObject |
asJsonObject()
Returns this value as
OracleJsonObject . |
default OracleJsonString |
asJsonString()
Returns this value as
OracleJsonString . |
default OracleJsonTimestamp |
asJsonTimestamp()
Returns this value as
OracleJsonTimestamp . |
default OracleJsonTimestampTZ |
asJsonTimestampTZ()
Returns this value as
OracleJsonTimestampTZ . |
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.
|
static final OracleJsonValue NULL
static final OracleJsonValue TRUE
static final OracleJsonValue FALSE
OracleJsonValue.OracleJsonType getOracleJsonType()
String toString()
<T> T wrap(Class<T> wrapper)
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 the
java.sql.Wrapper
interface which can be used to map back to an
instance of oracle.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
and javax.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 |
wrapper
- the interface to view this object as. Must be assignable to
javax.json.JsonValue
default OracleJsonObject asJsonObject()
OracleJsonObject
.
This method is equivalent to (OracleJsonObject)this
.ClassCastException
- if this value is not an instance of OracleJsonObject
.default OracleJsonArray asJsonArray()
OracleJsonArray
.
This method is equivalent to (OracleJsonArray)this
.ClassCastException
- if this value is not an instance of OracleJsonArray
.default OracleJsonString asJsonString()
OracleJsonString
.
This method is equivalent to (OracleJsonString)this
.ClassCastException
- if this value is not an instance of OracleJsonString
.default OracleJsonDecimal asJsonDecimal()
OracleJsonDecimal
.
This method is equivalent to (OracleJsonDecimal)this
.ClassCastException
- if this value is not an instance of OracleJsonDecimal
.default OracleJsonDouble asJsonDouble()
OracleJsonDouble
.
This method is equivalent to (OracleJsonDouble)this
.ClassCastException
- if this value is not an instance of OracleJsonDouble
.default OracleJsonFloat asJsonFloat()
OracleJsonFloat
.
This method is equivalent to (OracleJsonFloat)this
.ClassCastException
- if this value is not an instance of OracleJsonFloat
.default OracleJsonNumber asJsonNumber()
OracleJsonNumber
.
This method is equivalent to (OracleJsonNumber)this
.ClassCastException
- if this value is not an instance of OracleJsonNumber
.default OracleJsonIntervalDS asJsonIntervalDS()
OracleJsonIntervalDS
.
This method is equivalent to (OracleJsonIntervalDS)this
.ClassCastException
- if this value is not an instance of OracleJsonIntervalDS
.default OracleJsonIntervalYM asJsonIntervalYM()
OracleJsonIntervalYM
.
This method is equivalent to (OracleJsonIntervalYM)this
.ClassCastException
- if this value is not an instance of OracleJsonIntervalYM
.default OracleJsonTimestamp asJsonTimestamp()
OracleJsonTimestamp
.
This method is equivalent to (OracleJsonTimestamp)this
.ClassCastException
- if this value is not an instance of OracleJsonTimestamp
.default OracleJsonTimestampTZ asJsonTimestampTZ()
OracleJsonTimestampTZ
.
This method is equivalent to (OracleJsonTimestampTZ)this
.ClassCastException
- if this value is not an instance of OracleJsonTimestampTZ
.default OracleJsonDate asJsonDate()
OracleJsonDate
.
This method is equivalent to (OracleJsonDate)this
.ClassCastException
- if this value is not an instance of OracleJsonDate
.default OracleJsonBinary asJsonBinary()
OracleJsonBinary
.
This method is equivalent to (OracleJsonBinary)this
.ClassCastException
- if this value is not an instance of OracleJsonBinary
.