Responses inline On Wednesday, October 3, 2018 at 5:04:07 AM UTC-7, omid pourhadi wrote: > > Thank you. > > I had the same conversation here > > https://groups.google.com/forum/#!topic/protobuf/JwiAkWbEAYI > > and I came to conclusion that Any is for messages with type and it is not > good for java serialization I tried it and I got this error. > Type of the Any message does not match the given class. > > > You need to serialize and deserialize with the same Java class in order for it to work. The Any message contains both the bytes and the message type (as a string) which is how it knows to raise an error.
> Another problem is, since I don't know how to convert bytes (ByteString > proto in Java) in message to Java Object I had to manually parse the protos > in my application code here. > > https://github.com/omidp/grpc-crud/blob/master/grpc-server/src/main/java/com/omid/grpc/service/PersonServiceImpl.java#L68 > > <https://www.google.com/url?q=https%3A%2F%2Fgithub.com%2Fomidp%2Fgrpc-crud%2Fblob%2Fmaster%2Fgrpc-server%2Fsrc%2Fmain%2Fjava%2Fcom%2Fomid%2Fgrpc%2Fservice%2FPersonServiceImpl.java%23L68&sa=D&sntz=1&usg=AFQjCNEbfV9eHlB9pAbIqlAiGAHsoXA25w> > > what is the correct way of doing this ? > In your proto, request.getSearch().getFilter() is being treated as bytes. You need to declare that field as the message you want. > > > > On Wednesday, October 3, 2018 at 3:27:26 AM UTC+3:30, Benjamin Krämer > wrote: >> >> It looks like you wanted to keep the Pagination message independant of >> your Person message in >> https://github.com/omidp/grpc-crud/blob/master/grpc-proto/src/main/proto/main.proto >> >> Instead of doing it through bytes, you should prefer the Any type >> (google.protobuf.Any) which you already import but not use. This will allow >> you to unpack it as the correct type (PersonFilter) and is internally still >> stored as bytes. This also works across all languages which makes porting >> easier. It's never a good idea to do the (de-)serialization manually. >> > -- You received this message because you are subscribed to the Google Groups "grpc.io" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/grpc-io. To view this discussion on the web visit https://groups.google.com/d/msgid/grpc-io/eb3f6ee4-76db-41bd-a365-88d423868dc5%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
