Protobuf: Unable to add hiphen "-" in proto 3 field name

Created on 11 May 2018  路  3Comments  路  Source: protocolbuffers/protobuf

message Obsmsg {
message P-GLOBAL {
string latitude = 1;
string longitude = 2;
string altitude = 3;
}

P-GLOBAL p-global = 1;
}

I am unable to generate java class file if "-" contain in the field name.

question

Most helpful comment

@Nayan-Das Are you just trying to set the JSON field name? If so, you could try annotating the field like this:
PGlobal p_global = 1 [json_name = "p-global"];
I haven't tried using hypens in JSON field names but I assume it should work.

All 3 comments

@Nayan-Das I believe this is working as intended--we don't support hyphens in field names or other identifiers. You can use underscores, though.

I understand,we can not add "-" but is there any way we can annotate the field name for "-".
Like any other library (Jackson,Ebean,GSON) support annotation.
Example of GSON annotation-
@SerializedName("person-name")
String personName;

I can not change the field name .Please suggest is there any way around?

@Nayan-Das Are you just trying to set the JSON field name? If so, you could try annotating the field like this:
PGlobal p_global = 1 [json_name = "p-global"];
I haven't tried using hypens in JSON field names but I assume it should work.

Was this page helpful?
0 / 5 - 0 ratings