Problem/Context. I need to send some messages to a remote actor. These messages may contain objects of a class that is unknown on the recipient side. And I need to intercept such a situation in order to avoid a ClassNotFoundException.
One solution may consist in intercepting unknown classes at the time of message deserialization. Then, the message may be replaced by a different application-level message so that the remote actor can communicate to the sender that it doesn't have the required classes.
I don't know if such an interception is possible, because custom de/serializators must implement akka.serialization.Serializer which has the following method
def fromBinary(bytes: Array[Byte],
clazz: Option[Class[_]]): AnyRef
Now, the problem stems from the construction of the Class objects (which is done from Akka) for objects of an unknown class.
Is there a way to customize Akka deserialization at a lower-level point in order to accomodate my needs?
Other solutions.
FACT 1. Actually I discovered that there is an alternative to deserialization with Class type hint, namely deserialization with string manifest. Reference: http://doc.akka.io/docs/akka/2.4.0/scala/serialization.html#Serializer_with_String_Manifest
NOTE: it is NOT available for Akka < 2.4.0. It might matter as from Akka 2.4.0 support for Java 1.6/1.7 is dropped. This means that to use Akka 2.4 you are required to have Java 8.
FACT 2. I also discovered that you Akka does not necessarily provide you the type hint. You can disable the type hint in the following way
class MyOwnSerializer extends akka.serialization.Serializer {
override def includeManifest: Boolean = false // !!!