I have two applications communicating by Akka remote.
I have one class in my first application in a pachage a
:
@SerialVersionUID(42L)
case class A()
and the same one in my second application but in a different package b
:
@SerialVersionUID(42L)
case class A()
But when I get by an actor message with an instance of the class a
I get a java.lang.ClassNotFoundException: a.A
because of the different package names.
Is there a way to easily avoid this?
What you want would require a full classpath scan (what if there is a third mypackage3.A which has also the same SerialVersionUID? How does the JVM know that it has to deserialize mypackage1.A into another type?) and obviously SerialVersionUID is not meant for this. It is only meant to track serialization-compatibility across multiple version of the same class.
Have a read What is a serialVersionUID and why should I use it?
So you have two options: