public final class SerialValueCoder extends Object implements ValueCoder
A ValueCoder
that uses standard Java serialization to store and
retrieve object values. This class is related to DefaultValueCoder
.
When Persistit serializes or deserializes an object for which there is no
registered ValueCoder
, it implicitly constructs either a
DefaultValueCoder
or a SerialValueCoder
, depending
on the value of the serialOverride
property. See Persistit Object
Serialization for details.
This class creates a new java.io.ObjectInputStream
each time it
is called upon to deserialize an instance of its client class, or a
java.io.ObjectOutputStream
to serialize an instance. The format
of the stored data is specified by the Java Object Serialization Specification with one exception: the class
descriptor is replaced by a handle; an association between handles and class
descriptors is maintained in a separate metadata tree. This avoids
redundantly storing class descriptors for multiple instance of the same
class.
Constructor and Description |
---|
SerialValueCoder(Class<?> clazz) |
Modifier and Type | Method and Description |
---|---|
Object |
get(Value value,
Class<?> clazz,
CoderContext context)
Creates an instance of the supplied class, populates its state by
decoding the supplied
Value using standard Java
serialization, and returns it. |
void |
put(Value value,
Object object,
CoderContext context)
Encodes the supplied
Object into the supplied
Value using standard Java serialization. |
public SerialValueCoder(Class<?> clazz)
public Object get(Value value, Class<?> clazz, CoderContext context)
Creates an instance of the supplied class, populates its state by
decoding the supplied Value
using standard Java
serialization, and returns it. This method will be called only if this
ValueCoder
has been registered with the current
CoderManager
to encode objects having supplied Class
value. Persistit will never call this method to decode a value that was
null
when written because null values are handled by
built-in encoding logic.
get
in interface ValueCoder
value
- The Value
from which interior fields of the
object are to be retrievedclazz
- The class of the object to be returned.context
- An arbitrary object that can optionally be supplied by the
application to convey an application-specific context for the
operation. (See CoderContext
.) The default value is
null
. For SerialValueCoder
this
parameter is always ignored.Object
having the same class as the suppled
clazz
parameter.ConversionException
public void put(Value value, Object object, CoderContext context)
Encodes the supplied Object
into the supplied
Value
using standard Java serialization. This method will be
called only if this ValueCoder
has been registered with the
current CoderManager
to encode objects having the class of the
supplied object.
Upon completion of this method, the backing byte array of the
Value
and its size should be updated to reflect the appended
key segment. Use the methods Value.getEncodedBytes()
,
Value.getEncodedSize()
and Value.setEncodedSize(int)
to
manipulate the byte array directly. More commonly, the implementation of
this method will simply call the appropriate put
methods to
write the interior field values into the Value
object.
put
in interface ValueCoder
value
- The Value
to which the interior data of the
supplied Object
should be encodedobject
- The object value to encode. This parameter will never be
null
because Persistit encodes nulls with a
built-in encoding.context
- An arbitrary object that can optionally be supplied by the
application to convey an application-specific context for the
operation. (See CoderContext
.) The default value is
null
. For SerialValueCoder
this
parameter is always ignored.Copyright © 2025 Open Identity Platform Community. All rights reserved.