Class SerializerWithStringManifest
- java.lang.Object
- 
- akka.serialization.SerializerWithStringManifest
 
- 
- All Implemented Interfaces:
- Serializer
 - Direct Known Subclasses:
- AsyncSerializerWithStringManifest,- ClusterMessageSerializer,- MessageSerializer,- MiscMessageSerializer,- PayloadSerializer,- ReplicatedDataSerializer,- ReplicatorMessageSerializer,- ServiceKeySerializer,- TestSerializer
 
 public abstract class SerializerWithStringManifest extends java.lang.Object implements Serializer A Serializer represents a bimap between an object and an array of bytes representing that object.For serialization of data that need to evolve over time the SerializerWithStringManifestis recommended instead ofSerializerbecause the manifest (type hint) is aStringinstead of aClass. That means that the class can be moved/removed and the serializer can still deserialize old data by matching on theString. This is especially useful for Akka Persistence.The manifest string can also encode a version number that can be used in fromBinaryto deserialize in different ways to migrate old data to new domain objects.If the data was originally serialized with Serializerand in a later version of the system you change toSerializerWithStringManifestthe manifest string will be the full class name if you usedincludeManifest=true, otherwise it will be the empty string.Serializers are loaded using reflection during ActorSystemstart-up, where constructors are tried in order:- taking exactly one argument of type ExtendedActorSystem; this should be the preferred one because all reflective loading of classes during deserialization should use ExtendedActorSystem.dynamicAccess (seeDynamicAccess)
- taking exactly one argument of type ActorSystem
- taking exactly one argument of type ClassicActorSystemProvider
- without arguments
- taking two arguments of type ExtendedActorSystemandStringwhere the secondStringargument is the binding name
- taking two arguments of type ActorSystemandStringwhere the secondStringargument is the binding name
- taking two arguments of type ClassicActorSystemProviderandStringwhere the secondStringargument is the binding name
 Be sure to always use the DynamicAccessfor loading classes! This is necessary to avoid strange match errors and inequalities which arise from different class loaders loading the same class.
- 
- 
Constructor SummaryConstructors Constructor Description SerializerWithStringManifest()
 - 
Method SummaryAll Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract java.lang.ObjectfromBinary(byte[] bytes, java.lang.String manifest)Produces an object from an array of bytes, with an optional type-hint.java.lang.ObjectfromBinary(byte[] bytes, scala.Option<java.lang.Class<?>> manifest)Produces an object from an array of bytes, with an optional type-hint; the class should be loaded using ActorSystem.dynamicAccess.abstract intidentifier()Completely unique value to identify this implementation of Serializer, used to optimize network traffic.booleanincludeManifest()Returns whether this serializer needs a manifest in the fromBinary methodabstract java.lang.Stringmanifest(java.lang.Object o)Return the manifest (type hint) that will be provided in the fromBinary method.abstract byte[]toBinary(java.lang.Object o)Serializes the given object into an Array of Byte.- 
Methods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 - 
Methods inherited from interface akka.serialization.SerializerfromBinary, fromBinary
 
- 
 
- 
- 
- 
Method Detail- 
fromBinarypublic abstract java.lang.Object fromBinary(byte[] bytes, java.lang.String manifest) throws java.io.NotSerializableExceptionProduces an object from an array of bytes, with an optional type-hint.It's recommended to throw java.io.NotSerializableExceptioninfromBinaryif the manifest is unknown. This makes it possible to introduce new message types and send them to nodes that don't know about them. This is typically needed when performing rolling upgrades, i.e. running a cluster with mixed versions for while.NotSerializableExceptionis treated as a transient problem in the TCP based remoting layer. The problem will be logged and message is dropped. Other exceptions will tear down the TCP connection because it can be an indication of corrupt bytes from the underlying transport.- Throws:
- java.io.NotSerializableException
 
 - 
fromBinarypublic final java.lang.Object fromBinary(byte[] bytes, scala.Option<java.lang.Class<?>> manifest)Description copied from interface:SerializerProduces an object from an array of bytes, with an optional type-hint; the class should be loaded using ActorSystem.dynamicAccess.- Specified by:
- fromBinaryin interface- Serializer
 
 - 
identifierpublic abstract int identifier() Completely unique value to identify this implementation of Serializer, used to optimize network traffic. Values from 0 to 40 are reserved for Akka internal usage.- Specified by:
- identifierin interface- Serializer
 
 - 
includeManifestpublic final boolean includeManifest() Description copied from interface:SerializerReturns whether this serializer needs a manifest in the fromBinary method- Specified by:
- includeManifestin interface- Serializer
 
 - 
manifestpublic abstract java.lang.String manifest(java.lang.Object o) Return the manifest (type hint) that will be provided in the fromBinary method. Use""if manifest is not needed.
 - 
toBinarypublic abstract byte[] toBinary(java.lang.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. - Specified by:
- toBinaryin interface- Serializer
 
 
- 
 
-