Skip to content

Using field names based on json_name annotation in generated static code #992

Open
@cusher

Description

@cusher

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().

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions