E
- The Java array component type this codec handlespublic class ObjectArrayCodec<E> extends AbstractArrayCodec<E[]>
For example, to create a codec that maps list<text>
to String[]
, declare the
following:
ObjectArrayCodec<String> stringArrayCodec = new ObjectArrayCodec<>(
DataType.list(DataType.varchar()),
String[].class,
TypeCodec.varchar());
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 |
---|
ObjectArrayCodec(DataType.CollectionType cqlType,
Class<E[]> javaClass,
TypeCodec<E> eltCodec) |
Modifier and Type | Method and Description |
---|---|
E[] |
deserialize(ByteBuffer bytes,
ProtocolVersion protocolVersion)
Deserialize the given
ByteBuffer instance according to the CQL type handled by this
codec. |
protected void |
formatElement(StringBuilder output,
E[] array,
int index)
Format the
index th element of array to output . |
protected E[] |
newInstance(int size)
Create a new array instance with the given size.
|
protected void |
parseElement(String input,
E[] array,
int index)
Parse the
index th element of array from input . |
ByteBuffer |
serialize(E[] value,
ProtocolVersion protocolVersion)
Serialize the given value according to the CQL type handled by this codec.
|
format, parse
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, varint
public ObjectArrayCodec(DataType.CollectionType cqlType, Class<E[]> javaClass, TypeCodec<E> eltCodec)
public ByteBuffer serialize(E[] value, ProtocolVersion protocolVersion)
TypeCodec
Implementation notes:
null
input as the equivalent of an
empty collection.
serialize
in class TypeCodec<E[]>
value
- An instance of T; may be null
.protocolVersion
- the protocol version to use when serializing bytes
. In most
cases, the proper value to provide for this argument is the value returned by ProtocolOptions.getProtocolVersion()
(which is the protocol version in use by the driver).ByteBuffer
instance containing the serialized form of Tpublic E[] deserialize(ByteBuffer bytes, ProtocolVersion protocolVersion)
TypeCodec
ByteBuffer
instance according to the CQL type handled by this
codec.
Implementation notes:
null
or a default value for the corresponding Java type, if
applicable;
null
; they should return
empty collections instead (the driver's default collection codecs all comply with this
rule).
ByteBuffer
should never be consumed by read operations that modify
its current position; if necessary, ByteBuffer.duplicate()
duplicate} it before
consuming.
deserialize
in class TypeCodec<E[]>
bytes
- A ByteBuffer
instance containing the serialized form of T; may be null
or empty.protocolVersion
- the protocol version to use when serializing bytes
. In most
cases, the proper value to provide for this argument is the value returned by ProtocolOptions.getProtocolVersion()
(which is the protocol version in use by the driver).protected void formatElement(StringBuilder output, E[] array, int index)
AbstractArrayCodec
index
th element of array
to output
.formatElement
in class AbstractArrayCodec<E[]>
output
- The StringBuilder to write to.array
- The array to read from.index
- The element index.protected void parseElement(String input, E[] array, int index)
AbstractArrayCodec
index
th element of array
from input
.parseElement
in class AbstractArrayCodec<E[]>
input
- The String to read from.array
- The array to write to.index
- The element index.protected E[] newInstance(int size)
AbstractArrayCodec
newInstance
in class AbstractArrayCodec<E[]>
size
- The size of the array to instantiate.Copyright © 2012–2019. All rights reserved.