Package org.ehcache.spi.serialization
Interface Serializer<T>
-
- Type Parameters:
T- the type of the instances to serialize
- All Known Subinterfaces:
StatefulSerializer<T>
public interface Serializer<T>Defines the contract used to transform type instances to and from a serial form.Implementations must be thread-safe.
When used within the default serialization provider, there is an additional requirement. The implementations must define a constructor that takes in a
ClassLoader. TheClassLoadervalue may benull. If notnull, the class loader instance provided should be used during deserialization to load classes needed by the deserialized objects.The serialized object's class must be preserved; deserialization of the serial form of an object must return an object of the same class. The following contract must always be true:
object.getClass().equals( mySerializer.read(mySerializer.serialize(object)).getClass())- See Also:
SerializationProvider
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description booleanequals(T object, java.nio.ByteBuffer binary)Checks if the given instance and serial formrepresentthe same instance.Tread(java.nio.ByteBuffer binary)Reconstructs an instance from the given serial form.java.nio.ByteBufferserialize(T object)Transforms the given instance into its serial form.
-
-
-
Method Detail
-
serialize
java.nio.ByteBuffer serialize(T object) throws SerializerException
Transforms the given instance into its serial form.- Parameters:
object- the instance to serialize- Returns:
- the binary representation of the serial form
- Throws:
SerializerException- if serialization fails
-
read
T read(java.nio.ByteBuffer binary) throws java.lang.ClassNotFoundException, SerializerException
Reconstructs an instance from the given serial form.- Parameters:
binary- the binary representation of the serial form- Returns:
- the de-serialized instance
- Throws:
SerializerException- if reading the byte buffer failsjava.lang.ClassNotFoundException- if the type to de-serialize to cannot be found
-
equals
boolean equals(T object, java.nio.ByteBuffer binary) throws java.lang.ClassNotFoundException, SerializerException
Checks if the given instance and serial formrepresentthe same instance.- Parameters:
object- the instance to checkbinary- the serial form to check- Returns:
trueif both parameters represent equal instances,falseotherwise- Throws:
SerializerException- if reading the byte buffer failsjava.lang.ClassNotFoundException- if the type to de-serialize to cannot be found
-
-