I want to define a request message in gRPC which should have a Json Object as a field For e.g.
message UserRequest{
string name = 1;
string city = 2;
string email = 3;
metainfo = 4;//A Json Object variable which can have any number of elements
}
How do I represent the metainfo property within proto definition? I have tried using below definition but it didn't work.
message UserRequest{
string name = 1;
string city = 2;
string email = 3;
google.protobuf.Any metainfo = 4;
}
I think you want a .google.protobuf.Struct
, via struct.proto - this essentially encapsulates a map<string, Value> fields
, and is broadly akin to what you would want to describe via JSON. Additionally, Struct
has custom JSON handling, as mentioned in the file:
The JSON representation for
Struct
is JSON object.
So:
.google.protobuf.Struct metainfo = 4;
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