Get camel name from protocol buffer field

I have a protocol buffer message like this:

    message Person {

    optional string last_name = 1; 
    optional string first_name = 2;

    }

The generated java class is as follows:

 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 a java object is created, it uses the camel field name as lastName, firstName via the getLastName () and getFirstName () method. Is there a way to get the name of the camel field? I do not want to get the name of the source field: last_name, first_name and convert it again to the name of the camel name every time I want to getter and setter on my java object.

+3
source share
1 answer

Copy in the answer (hence the wiki, if not my answer) from Kenton Varda to the protobuf list :

, . . , .

+2

Source: https://habr.com/ru/post/1782621/


All Articles