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?
- The problem is similar to the one depicted in the following SO question, where a different solution has been proposed: Deserialize remote object to the narrowest accessible class
It would still be useful to have an answer there. However, that solution wouldn't be sufficient for me, because while it would be ok to restrict the interface, I would still need a class implementation with extra methods.