Reputation: 372
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;
}
Upvotes: 13
Views: 21404
Reputation: 1062510
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;
Upvotes: 20