-
-
Notifications
You must be signed in to change notification settings - Fork 285
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
akka serialization and scalapb #27
Comments
Fixes #27 Conflicts: compiler-plugin/src/main/scala/com/trueaccord/scalapb/compiler/ProtobufGenerator.scala scalapb-runtime/src/main/scala/com/trueaccord/scalapb/GeneratedMessageCompanion.scala
thx 👍 |
This is in 0.4.15 - let me know how if this helps. |
It works great, Akka correctly picks correct serializer, thanks 👍 Also thanks for being so quick :) |
Which serializer should akka be picking? I'm having trouble forcing it to pick the protobuf serializer. Missing the |
You need to implement your own serializer as described in http://doc.akka.io/docs/akka/snapshot/scala/serialization.html Akka's default proto serializer is for Java generated classes. |
Gotcha, thanks! On Tue, Oct 18, 2016, 6:07 PM Nadav Samet [email protected] wrote:
|
You can use my implementation for reference: I register it as akka {
actor {
serializers {
scalaProto = "ws.eiennohito.utils.serialization.ScalaProtobufSerializer"
}
serialization-bindings {
"com.trueaccord.scalapb.GeneratedMessage" = scalaProto
}
}
} |
The Akka protobuf serializer works I have used it successfully numerous times on ScalaPB generated classes. It uses reflection to determine whether or not the class adheres to the desired contract (
|
@nattyddubbs Nice, I didn't know that! @ZhangBanger can you share a minimal example with the problem you are seeing? |
I have this in my config:
Getting this error:
(Ignore the somewhat confusing naming of @nattyddubbs @thesamet Is this because |
For a little more background, my message type looks something like:
Another possibility is the nesting is not playing nicely? Looking into that as well. Update - I moved |
I think I have seen something similar before - Java reflection and nested companion objects. Let me know if this is something you'd like us to fix, by filing another issue. |
@ZhangBanger I add an individual entry for each message type that I'll be sending in between Actors in the serialization-binding entry. For example:
|
@nattyddubbs are you able to deal with nested messages? I tried individual entries as well without success |
@ZhangBanger I have not used the Akka built in Protobuf serializer for nested messages. Typically nested messages for our use cases would always remain nested and thus not need to be serialized individually. |
@ZhangBanger my solution works for nested messages. By the way, you can register only the common interface for akka as specified in its documentation. If you still want to register only several your classes, you need to specify class name for them which uses |
@eiennohito - gotcha, thanks! @thesamet - let me take another look and see if I can figure out what happened. Would be nice to not have to write more code / add more deps. |
@eiennohito That's really good to know. Maybe we'll look at using that approach in the future 👍 |
Would it make sense to have
com.trueaccord.scalapb.GeneratedMessage
andcom.trueaccord.scalapb.GeneratedEnum
extendjava.io.Serializable
. Reason for asking is that akka serialization picks the wrong serializer due to this:In case of ambiguity, i.e. the message implements several of the configured classes, the most specific configured class will be used, i.e. the one of which all other candidates are superclasses. If this condition cannot be met, because e.g. java.io.Serializable and MyOwnSerializable both apply and neither is a subtype of the other, a warning will be issued
I believe
com.google.protobuf.GeneratedMessage
implementsjava.io.Serializable
withserialVersionUID = 1L
.The text was updated successfully, but these errors were encountered: