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

fix: code generation for int64 map values in fromPartial and fromJson #395

Merged
merged 3 commits into from
Nov 21, 2021

Conversation

SchroederChris
Copy link
Contributor

Hi @stephenh,

I noticed that with --ts_proto_opt=forceLong=long, if you have a map with an int64 value (e.g. map<string, int64> data), the generated typescript code in fromJSON and fromPartial wasn't correct (it fell back to message.data[key] = Long(value), which didn't compile). I changed that to use Long.fromString in fromJSON (int64 should always be string in JSON, right?) and Long.fromValue in fromPartial.

As we don't use binary protobuf, I only checked these two methods.

Also, I unfortunately didn't figure out how to add a test for this, so I'll leave this to you.

Kind regards!

@SchroederChris SchroederChris changed the title fix code generation for int64 map values in fromPartial and fromJson fix: code generation for int64 map values in fromPartial and fromJson Nov 19, 2021
@stephenh
Copy link
Owner

@SchroederChris thanks for the PR; I've added some tests and a few more fixes. Going to merge, thanks!

@stephenh stephenh merged commit d3ea8eb into stephenh:main Nov 21, 2021
stephenh pushed a commit that referenced this pull request Nov 21, 2021
## [1.87.1](v1.87.0...v1.87.1) (2021-11-21)

### Bug Fixes

* code generation for int64 map values in fromPartial and fromJson ([#395](#395)) ([d3ea8eb](d3ea8eb))
@stephenh
Copy link
Owner

🎉 This PR is included in version 1.87.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

@SchroederChris
Copy link
Contributor Author

Thanks for the quick merge!

While implementing the changes in our codebase, I realized that it might be a good idea to also use Long.fromValue() instead of Long.fromString() in fromJSON. This would make the code more robust if called with an already parsed object. What do you think?

@stephenh
Copy link
Owner

@SchroederChris ah sure! That sgtm. Can you submit a PR with that change? Thanks!

@SchroederChris
Copy link
Contributor Author

👍 here it is: #405

@SchroederChris SchroederChris deleted the bugfix/int64_map_values branch November 22, 2021 14:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants