I read the akka serialization page, where they talk about serialization-bindings
as
serialization-bindings {
"java.lang.String" = java
"docs.serialization.Customer" = java
"com.google.protobuf.Message" = proto
"docs.serialization.MyOwnSerializable" = myown
"java.lang.Boolean" = myown
}
I am considering use of kyro serialization and wondering if there is a way to turn on kyro
serialization by default for complete application? rather than giving every class or package name?
Something like
serialization-bindings {
default = kyro
}
This is the way, I use kryo:
serializers {
kryo = "com.romix.akka.serialization.kryo.KryoSerializer"
}
serialization-bindings {
"com.ex.es.Msg" = kryo
"java.io.Serializable" = none
}
Similar to Kunal all my messages, that I send over the wire / store / serialize in any way extend that Msg
class. That's not only because I'm not sure wether there is a way to set a default serializer, but also to make it explicit for me, what is serialized in my application.
And now to give your actual question a try:
I also had to set "java.io.Serializable" = none
otherwise I got a warning, that it wasn't sure, which serializer to pick for my classes.
So this could imply, that case classes by default extend Serializable and make something like this work as a default setting:
serializers {
kryo = "com.romix.akka.serialization.kryo.KryoSerializer"
}
serialization-bindings {
"java.io.Serializable" = kryo
}
But that is only an educated guess and at the moment I have no possibility to test.
The way I do that is to make all my serializable classes extend a SerializableTrait
and then in my bindings I just specify my trait to be serialized using the custom serializer.
akka.actor {
serializers {
json-serializer = "io.example.MySerializerClass"
}
serialization-bindings {
"io.example.SerializableTrait" = json-serializer
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With