Skip to content

Support camelCase fields (via a json_names option).#142

Merged
thesayyn merged 5 commits intothesayyn:mainfrom
zacharyvoase:json-names
Jun 4, 2022
Merged

Support camelCase fields (via a json_names option).#142
thesayyn merged 5 commits intothesayyn:mainfrom
zacharyvoase:json-names

Conversation

@zacharyvoase
Copy link
Copy Markdown

I know this has been asked for a lot, so I decided to implement it. It turns out FieldDescriptorProto already has a json_name for each field, as generated by the protobuf compiler, so this option just causes the compiler to use that (instead of fieldDescriptor.name) for all generated descriptors. Obviously I left in the default behavior of using the names from the proto definitions as-is, for backwards compatibility.

Let me know if I need to add more tests; I wrote a simple smoke test that seems to work though.

@zacharyvoase
Copy link
Copy Markdown
Author

I should mention, this has the benefit that if the proto author overrides the JSON name manually, that will be used. e.g.:

message Msg {
  string a_field = 1 [json_name = "customFieldName"];
}

then the generated JS will use message.customFieldName.

@thesayyn
Copy link
Copy Markdown
Owner

thesayyn commented Jun 1, 2022

Hey. thanks for working on this. I will look into it sometime this week.

Copy link
Copy Markdown
Owner

@thesayyn thesayyn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! Thanks

@thesayyn thesayyn merged commit 1022c90 into thesayyn:main Jun 4, 2022
@thesayyn thesayyn mentioned this pull request Jul 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants