我想在 gRPC 中定义一个请求消息,它应该有一个 Json 对象作为字段
例如
message UserRequest{
string name = 1;
string city = 2;
string email = 3;
metainfo = 4;//A Json Object variable which can have any number of elements
}
如何在 proto 定义中表示元信息属性?
我试过使用下面的定义,但没有用。
message UserRequest{
string name = 1;
string city = 2;
string email = 3;
google.protobuf.Any metainfo = 4;
}
最佳答案
我想你想要一个 .google.protobuf.Struct
, 通过 struct.proto - 这基本上封装了一个 map<string, Value> fields
,并且大致类似于您想要通过 JSON 描述的内容。此外,Struct
具有自定义 JSON 处理,如文件中所述:
The JSON representation for
Struct
is JSON object.
所以:
.google.protobuf.Struct metainfo = 4;
关于java - 如何使用 Proto 定义表示 JSON 对象变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59561572/