have to create java pojo for the existing proto includes Map

妖精的绣舞 提交于 2020-01-02 10:04:36

问题


I have tried converting proto to java pojo . But got the error

[Stderr] Order.proto:12:18: Expected "required", "optional", or "repeated". [Stderr] Order.proto:12:21: Expected field name.

optional int32 orderID = 1; 
optional int32 quantity = 2;    
map<string,string> map_field = 4;
repeated string product = 3;

Please help me what needs to be changed. i searched on google protobuf developer site https://developers.google.com/protocol-buffers/docs/proto#maps It says that Map fields cannot be repeated, optional, or required

Please help me to resolve the issue.


回答1:


Maps are a new feature in protobuf 3.0 (aka "proto3"), which is still in alpha. You are probably using 2.x, in which case there are no maps. Your best bet is to use a repeated field:

repeated MyMap map_field = 4;
message MyMap {
  optional string key = 1;
  optional string value = 2;
}


来源:https://stackoverflow.com/questions/29407123/have-to-create-java-pojo-for-the-existing-proto-includes-map

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!