T - The Java type this codec serializes from and deserializes to.public abstract class ParsingCodec<T> extends TypeCodec<T>
TypeCodec that stores JAVA objects as serialized strings. This can serve as a
base for codecs dealing with XML or JSON formats.
This codec can be seen as a convenience base class to help implementing Java-to-XML or
Java-to-JSON mappings, but it comes with a performance penalty: each Java object is serialized in
two steps: first to a String, and then to a ByteBuffer, which means that each
serialization actually incurs in two potentially expensive operations being carried.
If you are using an XML or JSON library that supports writing Java objects directly to ByteBuffers, consider writing your own codec instead of using this one.
TypeCodec.AbstractCollectionCodec<E,C extends Collection<E>>, TypeCodec.AbstractMapCodec<K,V>, TypeCodec.AbstractTupleCodec<T>, TypeCodec.AbstractUDTCodec<T>, TypeCodec.PrimitiveBooleanCodec, TypeCodec.PrimitiveByteCodec, TypeCodec.PrimitiveDoubleCodec, TypeCodec.PrimitiveFloatCodec, TypeCodec.PrimitiveIntCodec, TypeCodec.PrimitiveLongCodec, TypeCodec.PrimitiveShortCodec| Constructor and Description |
|---|
ParsingCodec(Class<T> javaType) |
ParsingCodec(TypeCodec<String> innerCodec,
Class<T> javaType) |
ParsingCodec(TypeCodec<String> innerCodec,
TypeToken<T> javaType) |
ParsingCodec(TypeToken<T> javaType) |
| Modifier and Type | Method and Description |
|---|---|
T |
deserialize(ByteBuffer bytes,
ProtocolVersion protocolVersion) |
String |
format(T value) |
protected abstract T |
fromString(String value)
Parse the given string into an object; no special CQL unquoting should be applied here.
|
T |
parse(String value) |
ByteBuffer |
serialize(T value,
ProtocolVersion protocolVersion) |
protected abstract String |
toString(T value)
Return the String representation of the given object; no special CQL quoting should be applied
here.
|
accepts, accepts, accepts, accepts, ascii, bigint, blob, cboolean, cdouble, cfloat, cint, counter, custom, date, decimal, duration, getCqlType, getJavaType, inet, list, map, set, smallInt, time, timestamp, timeUUID, tinyInt, toString, tuple, userType, uuid, varchar, varintpublic ByteBuffer serialize(T value, ProtocolVersion protocolVersion) throws InvalidTypeException
serialize in class TypeCodec<T>InvalidTypeExceptionpublic T deserialize(ByteBuffer bytes, ProtocolVersion protocolVersion) throws InvalidTypeException
deserialize in class TypeCodec<T>InvalidTypeExceptionpublic String format(T value) throws InvalidTypeException
format in class TypeCodec<T>InvalidTypeExceptionpublic T parse(String value) throws InvalidTypeException
parse in class TypeCodec<T>InvalidTypeExceptionprotected abstract String toString(T value)
value - the value to convert into a stringprotected abstract T fromString(String value)
value - the string to parseCopyright © 2012–2018. All rights reserved.