Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fromJSON should accept both snake_case and camelCase keys #1012

Open
jdbp-classpass opened this issue Mar 5, 2024 · 1 comment
Open

fromJSON should accept both snake_case and camelCase keys #1012

jdbp-classpass opened this issue Mar 5, 2024 · 1 comment
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@jdbp-classpass
Copy link

The proto3 JSON specification says that Proto3 JSON parsers are required to accept both the converted lowerCamelCase name and the proto field name.. This seems to mean that, given a message with a field like "my_field", the fromJson method should accept either {"my_field": "value"} or {"myField": "value"}. Google's standard protobuf Java library works this way.

Currently the ts-proto generated fromJSON only accepts one or the other, as determined by the snakeToCamel option. Ideally snakeToCamel would only affect toJSON (which is how the spec describes it), but fromJSON would accept either one regardless.

@stephenh
Copy link
Owner

stephenh commented Mar 6, 2024

Hi @jdbp-classpass , yep, that is correct. I think we've not implemented this yet because I assume most companies just pick "either snake or camel" are their company's internal standard, and then don't deviate from that.

If you'd like to submit a PR that teaches fromJSON to support either, ideally behind a flag (like another snakeToCamel option I assume), so that current users don't pay for the code size & perf of checking two keys, that would be great! Thanks!

@stephenh stephenh added enhancement New feature or request help wanted Extra attention is needed labels Mar 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants