必须为现有的 proto 包括 Map 创建 java pojo [英] have to create java pojo for the existing proto includes Map
问题描述
我尝试将 proto 转换为 java pojo .但得到了错误
I have tried converting proto to java pojo . But got the error
[Stderr] Order.proto:12:18:应为必需"、可选"或重复".[Stderr] Order.proto:12:21:预期的字段名称.
[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;
请帮助我需要更改的内容.我在谷歌 protobuf 开发者网站上搜索过https://developers.google.com/protocol-buffers/docs/proto#maps它说 Map 字段不能重复、可选或必填
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
请帮我解决问题.
推荐答案
Maps 是 protobuf 3.0(又名proto3")中的一个新特性,它仍处于 alpha 阶段.您可能使用的是 2.x,在这种情况下没有映射.最好的办法是使用重复字段:
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;
}
这篇关于必须为现有的 proto 包括 Map 创建 java pojo的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!