从协议缓冲区字段中获取骆驼名称
我有一个这样的协议缓冲区消息:
message Person {
optional string last_name = 1;
optional string first_name = 2;
}
java 生成的类如下所示:
public static final class Person extends
com.google.protobuf.GeneratedMessage {
// Use Person.newBuilder() to construct.
...... constructor stuffs
// optional string first_name = 1;
public static final int FIRST_NAME_FIELD_NUMBER = 1;
private boolean hasFirstName;
private java.lang.String firstName_ = "";
public boolean hasFirstName() { return hasFirstName; }
public java.lang.String getFirstName() { return firstName_; }
// optional string last_name = 2;
public static final int LAST_NAME_FIELD_NUMBER = 2;
private boolean hasLastName;
private java.lang.String lastName_ = "";
public boolean hasLastName() { return hasLastName; }
public java.lang.String getLastName() { return lastName_; }
............
}
生成 java 对象时,它通过调用 getLastName() 和 getFirstName() 方法使用驼峰字段名称作为 lastName, firstName 。有没有办法获取骆驼字段名称?我不想获取原始字段名称 name :last_name、first_name 并在每次我想做的时候再次将其转换为驼峰字段名称 我的 java 对象上的 getter 和 setter。
I have a protocol buffer message like this:
message Person {
optional string last_name = 1;
optional string first_name = 2;
}
The java generated class looks like this:
public static final class Person extends
com.google.protobuf.GeneratedMessage {
// Use Person.newBuilder() to construct.
...... constructor stuffs
// optional string first_name = 1;
public static final int FIRST_NAME_FIELD_NUMBER = 1;
private boolean hasFirstName;
private java.lang.String firstName_ = "";
public boolean hasFirstName() { return hasFirstName; }
public java.lang.String getFirstName() { return firstName_; }
// optional string last_name = 2;
public static final int LAST_NAME_FIELD_NUMBER = 2;
private boolean hasLastName;
private java.lang.String lastName_ = "";
public boolean hasLastName() { return hasLastName; }
public java.lang.String getLastName() { return lastName_; }
............
}
When java object is generated it uses camel field name as lastName, firstName through method call getLastName() and getFirstName(). Is there a way to get the camel field name out? I don't want to get the original field name name : last_name, first_name and convert it again to camel field name every time that I want to do
getter and setter on my java object.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
复制 Kenton Varda 在 protobuf列表:
Copying in an answer (hence wiki, as not my answer) from Kenton Varda on the protobuf list: