Interface Serializer

All Known Subinterfaces:
BaseSerializer
All Known Implementing Classes:
AbstractSerializationSupport, AsyncSerializerWithStringManifest, AsyncSerializerWithStringManifestCS, ByteArraySerializer, ClusterMessageSerializer, DisabledJavaSerializer, JavaSerializer, JSerializer, MessageContainerSerializer, MessageSerializer, MessageSerializer, MiscMessageSerializer, NullSerializer, NullSerializer$, ProtobufSerializer, ReplicatedDataSerializer, ReplicatorMessageSerializer, SerializerWithStringManifest, ServiceKeySerializer, SnapshotSerializer, SystemMessageSerializer, TestJavaSerializer, TestSerializer

public interface Serializer
A Serializer represents a bimap between an object and an array of bytes representing that object.

Serializers are loaded using reflection during pekko.actor.ActorSystem start-up, where two constructors are tried in order:

  • taking exactly one argument of type pekko.actor.ExtendedActorSystem; this should be the preferred one because all reflective loading of classes during deserialization should use ExtendedActorSystem.dynamicAccess (see pekko.actor.DynamicAccess), and
  • without arguments, which is only an option if the serializer does not load classes using reflection.

Be sure to always use the pekko.actor.DynamicAccess for loading classes! This is necessary to avoid strange match errors and inequalities which arise from different class loaders loading the same class.

  • Method Summary

    Modifier and Type
    Method
    Description
    fromBinary(byte[] bytes)
    Java API: deserialize without type hint
    fromBinary(byte[] bytes, Class<?> clazz)
    Java API: deserialize with type hint
    fromBinary(byte[] bytes, scala.Option<Class<?>> manifest)
    Produces an object from an array of bytes, with an optional type-hint; the class should be loaded using ActorSystem.dynamicAccess.
    int
    Completely unique value to identify this implementation of Serializer, used to optimize network traffic.
    boolean
    Returns whether this serializer needs a manifest in the fromBinary method
    byte[]
    Serializes the given object into an Array of Byte.
  • Method Details

    • fromBinary

      Object fromBinary(byte[] bytes, scala.Option<Class<?>> manifest) throws NotSerializableException
      Produces an object from an array of bytes, with an optional type-hint; the class should be loaded using ActorSystem.dynamicAccess.
      Throws:
      NotSerializableException
    • fromBinary

      Object fromBinary(byte[] bytes)
      Java API: deserialize without type hint
    • fromBinary

      Object fromBinary(byte[] bytes, Class<?> clazz) throws NotSerializableException
      Java API: deserialize with type hint
      Throws:
      NotSerializableException
    • identifier

      int identifier()
      Completely unique value to identify this implementation of Serializer, used to optimize network traffic. Values from 0 to 40 are reserved for Pekko internal usage.
    • includeManifest

      boolean includeManifest()
      Returns whether this serializer needs a manifest in the fromBinary method
    • toBinary

      byte[] toBinary(Object o)
      Serializes the given object into an Array of Byte.

      Note that the array must not be mutated by the serializer after it has been returned.