Interface Serializer

All Known Subinterfaces:
PofContext
All Known Implementing Classes:
ConfigurablePofContext, DefaultSerializer, MultiplexingSerializer, NullImplementation.NullPofContext, SafeConfigurablePofContext, SimplePofContext

public interface Serializer
The Serializer interface provides the capability of reading and writing a Java object from and to an in-memory buffer.

Serializer implementations should implement the ClassLoaderAware interface if they need access to a ClassLoader. However, to support hot-deploying containers, it is important that a Serializer not hold any strong references to that ClassLoader, or to any Class objects obtained from that ClassLoader.

Note: it is extremely important that objects that are equivalent according to their "equals()" implementation produce equivalent serialized streams. Violating this relationship will result in non-deterministic behavior for many Coherence services.

Since:
Coherence 3.2
Author:
cp/jh 2007.07.21
See Also:
  • Method Details

    • serialize

      void serialize(WriteBuffer.BufferOutput out, Object o) throws IOException
      Serialize an object to a WriteBuffer by writing its state using the specified BufferOutput object.

      Note: Starting with Coherence 12.2.1 classes that need to designate an alternative object to be used by the Serializer when writing the object to the buffer should implement the SerializationSupport.writeReplace() method.

      Parameters:
      out - the BufferOutput with which to write the object's state
      o - the object to serialize
      Throws:
      IOException - if an I/O error occurs
    • deserialize

      default Object deserialize(ReadBuffer.BufferInput in) throws IOException
      Deserialize an object from a ReadBuffer by reading its state using the specified BufferInput object.

      Note: Starting with Coherence 12.2.1 classes that need to designate an alternative object to be returned by the Serializer after an object is deserialized from the buffer should implement the SerializationSupport.readResolve() method.

      Parameters:
      in - the BufferInput with which to read the object's state
      Returns:
      the deserialized user type instance
      Throws:
      IOException - if an I/O error occurs
    • deserialize

      default <T> T deserialize(ReadBuffer.BufferInput in, Class<? extends T> clazz) throws IOException
      Deserialize an object as an instance of the specified class by reading its state using the specified BufferInput object.

      Note: Starting with Coherence 12.2.1 classes that need to designate an alternative object to be returned by the Serializer after an object is deserialized from the buffer should implement the SerializationSupport.readResolve() method.

      Type Parameters:
      T - the class to deserialize to
      Parameters:
      in - the BufferInput with which to read the object's state
      clazz - the type of the object to deserialize
      Returns:
      the deserialized user type instance
      Throws:
      IOException - if an I/O error occurs
      Since:
      12.2.1.4
    • getName

      default String getName()
      Return the name of this serializer.
      Returns:
      the name of this serializer
      Since:
      12.2.1.4
    • discoverSerializers

      static Map<String,SerializerFactory> discoverSerializers()
      Return a Map of SerializerFactory instances discovered on the class path.
      Returns:
      a Map of SerializerFactory instances discovered on the class path
    • discoverSerializers

      static Map<String,SerializerFactory> discoverSerializers(ClassLoader loader)
      Return a Map of SerializerFactory instances discovered on the class path.
      Parameters:
      loader - the ClassLoader to use to discover any serializers
      Returns:
      a Map of SerializerFactory instances discovered on the class path