Reputation: 961
I'm looking to create a gRPC response that returns a list of maps. Here is what I imagined the structure being:
message GetSettingsResponse {
repeated map<string, string> settings = 1;
}
Repeating maps is not supported, however, and I had to nest the map in a separate message to make it work:
message GetSettingsResponse {
repeated Setting settings = 1;
}
message Setting {
map<string, string> setting = 1;
}
This works, but it forces us to write some confusing code on both the client and server. Is there any way to avoid this solution and get closer to my desired structure?
Upvotes: 6
Views: 5205
Reputation: 3
I came into a similar issue, that I'd like a Message corresponding to List<Map<String,Object>>
in Java.
And I solved my problem by defining Message like this:
import "google/protobuf/struct.proto";
message MyMessage {
repeated google.protobuf.Struct mapList = 1;
}
Hope it'll help.
Upvotes: 0
Reputation: 1062865
No, basically. What you have is the closest you can do in protobuf.
Upvotes: 8