Relates to #27
When using a nested message, Java reflection fails to see the parseFrom method but has no trouble with toByteArray.
Reproduction steps
Created a nested message
message OuterMessage {
message InnerMessage {
string hiField = 1;
}
string helloField = 1;
...
}
Try to send just the inner message in a remote actor setting, i.e. through the PubSubMediator to a remote actor
mediator ! Publish(InnerMessage("hello"))
Using these settings:
actor {
provider = "akka.cluster.ClusterActorRefProvider"
serializers {
proto = "akka.remote.serialization.ProtobufSerializer"
}
serialization-bindings {
"com.trueaccord.scalapb.GeneratedMessage" = proto
}
}
The serializer throws an NoSuchMethodException from not being able to find the parseFrom method. This is coming from this line -> akka.remote.serialization.ProtobufSerializer.scalaLL69:
if (method eq null) clazz.getDeclaredMethod("parseFrom", ProtobufSerializer.ARRAY_OF_BYTE_ARRAY: _*)
@nadavsr will decide, but I think that compatibility with akka's default protobuf serializer is out of scope of ScalaPB. Its messages even does not implement protobuf's message interface.
Gotcha. Yes, from what I can tell, the issue is on the akka protobuf side. The nested class that is generated by ScalaPB looks consistent.
The culprit is that from some reason the scala compiler does not generate static methods for methods defined in a companion object of a nested class (but does so for companion objects of top level classes). This is why parseFrom isn't found.
I wrote a quick implementation Akka serializer that works with ScalaPB. Can you give it a try?
https://gist.github.com/thesamet/5d0349b40d3dc92859a1a2eafba448d5
Thanks for sending, very helpful!
Most helpful comment
The culprit is that from some reason the scala compiler does not generate static methods for methods defined in a companion object of a nested class (but does so for companion objects of top level classes). This is why
parseFromisn't found.I wrote a quick implementation Akka serializer that works with ScalaPB. Can you give it a try?
https://gist.github.com/thesamet/5d0349b40d3dc92859a1a2eafba448d5