必须为现有的 proto 包括 Map 创建 java pojo [英] have to create java pojo for the existing proto includes Map

查看:40
本文介绍了必须为现有的 proto 包括 Map 创建 java pojo的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试将 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆