public class Jsr353JsonCodec
extends com.datastax.driver.core.TypeCodec<javax.json.JsonStructure>
JsonStructure to
a CQL varchar column.
This codec handles the Java type JsonStructure.
It is therefore required that values are set and retrieved using that exact Java type;
users should manually downcast to either JsonObject or JsonArray,
as in the example below:
// setting values
JsonObject myObject = ...
PreparedStatement ps = ...
// set values using JsonStructure as target Java type
BoundStatement bs = ps.bind().set(1, myObject, JsonStructure.class);
// retrieving values
Row row = session.execute(bs).one();
// use JsonStructure as target Java type to retrieve values
JsonStructure json = row.get(0, JsonStructure.class);
if (json instanceof JsonObject) {
myObject = (JsonObject) json;
...
}
Note that at runtime, this codec requires the presence of both JSR-353 API
and a JSR-353-compatible runtime library, such as
JSR-353's reference implementation.
If you use Maven, this can be done by declaring the following dependencies in your project:
<dependency>
<groupId>javax.json</groupId>
<artifactId>javax.json-api</artifactId>
<version>1.0</version>
</dependency>
<p/>
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>javax.json</artifactId>
<version>1.0.4</version>
</dependency>
com.datastax.driver.core.TypeCodec.AbstractCollectionCodec<E,C extends Collection<E>>, com.datastax.driver.core.TypeCodec.AbstractMapCodec<K,V>, com.datastax.driver.core.TypeCodec.AbstractTupleCodec<T>, com.datastax.driver.core.TypeCodec.AbstractUDTCodec<T>, com.datastax.driver.core.TypeCodec.PrimitiveBooleanCodec, com.datastax.driver.core.TypeCodec.PrimitiveByteCodec, com.datastax.driver.core.TypeCodec.PrimitiveDoubleCodec, com.datastax.driver.core.TypeCodec.PrimitiveFloatCodec, com.datastax.driver.core.TypeCodec.PrimitiveIntCodec, com.datastax.driver.core.TypeCodec.PrimitiveLongCodec, com.datastax.driver.core.TypeCodec.PrimitiveShortCodec| Constructor and Description |
|---|
Jsr353JsonCodec() |
Jsr353JsonCodec(Map<String,?> config) |
| Modifier and Type | Method and Description |
|---|---|
javax.json.JsonStructure |
deserialize(ByteBuffer bytes,
com.datastax.driver.core.ProtocolVersion protocolVersion) |
String |
format(javax.json.JsonStructure value) |
javax.json.JsonStructure |
parse(String value) |
ByteBuffer |
serialize(javax.json.JsonStructure value,
com.datastax.driver.core.ProtocolVersion protocolVersion) |
accepts, accepts, accepts, accepts, ascii, bigint, blob, cboolean, cdouble, cfloat, cint, counter, custom, date, decimal, getCqlType, getJavaType, inet, list, map, set, smallInt, time, timestamp, timeUUID, tinyInt, toString, tuple, userType, uuid, varchar, varintpublic ByteBuffer serialize(javax.json.JsonStructure value, com.datastax.driver.core.ProtocolVersion protocolVersion) throws com.datastax.driver.core.exceptions.InvalidTypeException
serialize in class com.datastax.driver.core.TypeCodec<javax.json.JsonStructure>com.datastax.driver.core.exceptions.InvalidTypeExceptionpublic javax.json.JsonStructure deserialize(ByteBuffer bytes, com.datastax.driver.core.ProtocolVersion protocolVersion) throws com.datastax.driver.core.exceptions.InvalidTypeException
deserialize in class com.datastax.driver.core.TypeCodec<javax.json.JsonStructure>com.datastax.driver.core.exceptions.InvalidTypeExceptionpublic String format(javax.json.JsonStructure value) throws com.datastax.driver.core.exceptions.InvalidTypeException
format in class com.datastax.driver.core.TypeCodec<javax.json.JsonStructure>com.datastax.driver.core.exceptions.InvalidTypeExceptionpublic javax.json.JsonStructure parse(String value) throws com.datastax.driver.core.exceptions.InvalidTypeException
parse in class com.datastax.driver.core.TypeCodec<javax.json.JsonStructure>com.datastax.driver.core.exceptions.InvalidTypeExceptionCopyright © 2012–2018. All rights reserved.