protobuf.js version: 6.8.0
I've run into an issue a few times when parsing JSON data into the statically generated classes, when the fields in the JSON data are named using using the json_name annotation for the field names instead of the normal field names.
For example, if a proto file looks like:
import "google/api/annotations.proto";
import "otherstuff.proto";
message MyClass {
repeated Thing thing = 1 [json_name="my_things"];
}
And you are parsing in the object like
const myObject = MyClass.fromObject(someObjectParsedFromJsonData);
the object field currently needs to be named thing instead of my_things.
It would be nice if the alternate naming scheme could be used directly, either through a command line switch or using another method like fromJson() in place of fromObject().
The option you are looking for is keepCase. It's available in Root.load, parse and pbjs (--keep-case). If it's not specified, fields are converted to camelCase. (Or is there something broken?)
I'm already using --keep-case. Afaict that only, as you indicate, tells it not to convert to camel case. I'm looking for an option to parse in fields where the json_name is different altogether like in my example.
Most helpful comment
I'm already using --keep-case. Afaict that only, as you indicate, tells it not to convert to camel case. I'm looking for an option to parse in fields where the json_name is different altogether like in my example.