Reputation: 477
I Want to Return a JSON response from server to client in gRPC.
one possible way is to convert it to string return the response then convert back to Json Object in client side, but i want to know can we do better?.
i am doing some google and found we can do it with the help of google.protobuf.struct but didn't actually find any good example.
i want an example how i can use it as JSON in java.
Upvotes: 0
Views: 10443
Reputation: 610
If you are using proto3, one option is to define a protobuf message that mirrors the JSON object you wish to populate. Then you can use JsonFormat
to convert between protobuf and JSON.
Using a com.google.protobuf.Struct
instead of a self-defined message can also work. There is an example shown in the similar question.
Upvotes: 1