public class MapSerializer<T extends java.util.Map> extends Serializer<T>
Map
interface.
With the default constructor, a map requires a 1-3 byte header and an extra 4 bytes is written for each key/value pair.
Modifier and Type | Class and Description |
---|---|
static interface |
MapSerializer.BindMap
|
Constructor and Description |
---|
MapSerializer() |
Modifier and Type | Method and Description |
---|---|
T |
copy(Kryo kryo,
T original)
Returns a copy of the specified object.
|
protected T |
create(Kryo kryo,
Input input,
java.lang.Class<? extends T> type,
int size)
Used by
read(Kryo, Input, Class) to create the new object. |
protected T |
createCopy(Kryo kryo,
T original) |
java.lang.Class |
getKeyClass() |
Serializer |
getKeySerializer() |
java.lang.Class |
getValueClass() |
Serializer |
getValueSerializer() |
T |
read(Kryo kryo,
Input input,
java.lang.Class<? extends T> type)
Reads bytes and returns a new object of the specified concrete type.
|
void |
setKeyClass(java.lang.Class keyClass)
The concrete class of the keys for this map, or null if it is not known.
|
void |
setKeyClass(java.lang.Class keyClass,
Serializer keySerializer)
Sets both
setKeyClass(Class) and setKeySerializer(Serializer) . |
void |
setKeysCanBeNull(boolean keysCanBeNull) |
void |
setKeySerializer(Serializer keySerializer)
The serializer to be used for the keys in this map, or null to use the serializer registered with
Kryo for the
type. |
void |
setValueClass(java.lang.Class valueClass)
The concrete class of the values for this map, or null if it is not known.
|
void |
setValueClass(java.lang.Class valueClass,
Serializer valueSerializer)
Sets both
setValueClass(Class) and setValueSerializer(Serializer) . |
void |
setValuesCanBeNull(boolean valuesCanBeNull) |
void |
setValueSerializer(Serializer valueSerializer)
The serializer to be used for this field, or null to use the serializer registered with
Kryo for the type. |
void |
write(Kryo kryo,
Output output,
T map)
Writes the bytes for the object to the output.
|
protected void |
writeHeader(Kryo kryo,
Output output,
T map)
Can be overidden to write data needed for
create(Kryo, Input, Class, int) . |
getAcceptsNull, isImmutable, setAcceptsNull, setImmutable
public void setKeysCanBeNull(boolean keysCanBeNull)
keysCanBeNull
- False if all keys are not null. This saves 1 byte per key if keyClass is set. True if it is not known
(default).public void setKeyClass(java.lang.Class keyClass)
public java.lang.Class getKeyClass()
public void setKeyClass(java.lang.Class keyClass, Serializer keySerializer)
setKeyClass(Class)
and setKeySerializer(Serializer)
.public void setKeySerializer(Serializer keySerializer)
Kryo
for the
type. Default is null.public Serializer getKeySerializer()
public void setValueClass(java.lang.Class valueClass)
public java.lang.Class getValueClass()
public void setValueClass(java.lang.Class valueClass, Serializer valueSerializer)
setValueClass(Class)
and setValueSerializer(Serializer)
.public void setValueSerializer(Serializer valueSerializer)
Kryo
for the type. Default
is null.public Serializer getValueSerializer()
public void setValuesCanBeNull(boolean valuesCanBeNull)
valuesCanBeNull
- True if values are not null. This saves 1 byte per value if keyClass is set. False if it is not
known (default).public void write(Kryo kryo, Output output, T map)
Serializer
This method should not be called directly, instead this serializer can be passed to Kryo
write methods that accept a
serialier.
write
in class Serializer<T extends java.util.Map>
map
- May be null if Serializer.getAcceptsNull()
is true.protected void writeHeader(Kryo kryo, Output output, T map)
create(Kryo, Input, Class, int)
. The default implementation does
nothing.protected T create(Kryo kryo, Input input, java.lang.Class<? extends T> type, int size)
read(Kryo, Input, Class)
to create the new object. This can be overridden to customize object creation, eg
to call a constructor with arguments. The default implementation uses Kryo.newInstance(Class)
with a special case
for HashMap.public T read(Kryo kryo, Input input, java.lang.Class<? extends T> type)
Serializer
Before Kryo can be used to read child objects, Kryo.reference(Object)
must be called with the parent object to
ensure it can be referenced by the child objects. Any serializer that uses Kryo
to read a child object may need to
be reentrant.
This method should not be called directly, instead this serializer can be passed to Kryo
read methods that accept a
serialier.
read
in class Serializer<T extends java.util.Map>
Serializer.getAcceptsNull()
is true.public T copy(Kryo kryo, T original)
Serializer
Serializer.isImmutable()
is true,
else throws KryoException
. Subclasses can optionall override this method to support Kryo.copy(Object)
.
Before Kryo can be used to copy child objects, Kryo.reference(Object)
must be called with the copy to ensure it can
be referenced by the child objects. A serializer that uses Kryo
to copy a child object may need to be reentrant.
This method should not be called directly, instead this serializer can be passed to Kryo
copy methods that accept a
serialier.
copy
in class Serializer<T extends java.util.Map>
Copyright © 2018. All Rights Reserved.