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

toJSON methods don't respect useDate=false #935

Closed
roboslone opened this issue Oct 3, 2023 · 7 comments · Fixed by #937
Closed

toJSON methods don't respect useDate=false #935

roboslone opened this issue Oct 3, 2023 · 7 comments · Fixed by #937
Labels

Comments

@roboslone
Copy link
Contributor

This leads to precision loss.
I'm using useDate=false, which affects generated objects, but doesn't affect toJSON method.

@stephenh stephenh changed the title google.protobuf.Timestamp fields are converted to Date using Message.toJSON toJSON methods don't respect useDate=false Oct 3, 2023
@stephenh
Copy link
Owner

stephenh commented Oct 3, 2023

Huh, I was a little surprised toJSON doesn't check for useDate, but I guess it makes sense...

Fwiw @roboslone if you could submit a PR for this, that'd be great! Maybe find an integration test that has a parameters.txt with useDate=false in it, and reproduce a toJSON method observing the precision loss that you mention.

Thanks!

@roboslone
Copy link
Contributor Author

Sure, I'll give this a try.

@kirill-gadzhiev
Copy link

I noticed it today too, and it's really strange that no one had spotted it yet

@roboslone
Copy link
Contributor Author

yarn build:test doesn't work on my machine (macOS, M1) – alpine refuses to execute protoc with weird errors about libc. However, I was able to fix this by changing base image to node:current-slim. I ran all existing tests locally, everything is fine.

I could revert this change after I'm finished with this issue, or I could keep it so more people are able to run tests.

@stephenh What do you think?

@roboslone
Copy link
Contributor Author

Kept base image change for now, let me know if you want it reverted.

stephenh pushed a commit that referenced this issue Oct 4, 2023
## [1.159.3](v1.159.2...v1.159.3) (2023-10-04)

### Bug Fixes

* toJSON methods don't respect useDate=false ([#935](#935)) ([#937](#937)) ([acdfb0a](acdfb0a))
@stephenh
Copy link
Owner

stephenh commented Oct 4, 2023

🎉 This issue has been resolved in version 1.159.3 🎉

The release is available on:

Your semantic-release bot 📦🚀

@sheinbergon
Copy link

sheinbergon commented Nov 16, 2023

Might I argue this a bad/wrong fix for the non-issue?

toJSON() is strictly meant to generate protojson matching json representations.
It's fine if someone wants to keep useDate=false for object representation it's fine, but mostly - a thing of its own

This fix completely breaks the gRPC agenda of any language any platform compatibility, as protojsons can now be ts-proto compatible only

I believe there was a reason why useDate didn't apply to json representations.

We have a JVM/Python/Node JS ecosystem and we used useDate=false, but relied on the json repesentation to be protojson compatible. This fix completey broke everything for us and we need to downgrade the ts-proto version ATM.

I think we should parameterize this option, or create another param (useDateJson=false) to allow for better compatiblity.

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 a pull request may close this issue.

4 participants