You most certainly can!
When sending objects over the network, they must be turned into bytes on one end, and turned back into objects on the other end. This is called 'Serialization'.
In Akka the serialization mechanism used for messages travelling from one actor system to another is highly configurable: you shouldn't do it in your own actors, but leave it up to Akka's serialization infrastructure (and configure that to your liking).
By default akka uses the built-in 'Java serialization'. This mostly works, but as you noticed is pretty picky about having the exact same class on both sides of the connection. Also, it is not particularly fast. You should have seen a warning in the logging:
Using the default Java serializer for class [{}] which is not
recommended because of performance implications. Use another
serializer or disable this warning using the setting
akka.actor.warn-about-java-serializer-usage
To fix your problem you can either:
- Keep using Java serialization, and at least fixate the
serialVersionUID
as described in Vitaliy's answer.
- Switch to another serialization mechanism such as Protobuf.
If you don't care too much about performance and don't expect to do 'rolling upgrades' (where you might need to convert between different versions of the same message), Java serialization is certainly the easiest. It's important to be aware of its limitations, though.
Further documentation on how to configure akka's serialization mechanisms can be found at http://doc.akka.io/docs/akka/current/scala/serialization.html#serialization-scala
serialVersionUUID
– Vitalii Kotliarenko May 14 '16 at 13:03