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

Why uint64, int64 Protobuf-Type be serialize as String JSON-Type in MessageToJsonString()? #2679

Closed
david9991 opened this issue Feb 7, 2017 · 2 comments

Comments

@david9991
Copy link

Why uint64, int64 Protobuf-Type be serialize as String JSON-Type in MessageToJsonString()?
I tried to use uint64 or int64 to save the Timestamp, and convert it to JSON by MessageToJsonString()
Here is a sample output:

{"timestamp":"1486454809",
"nanosecond":549593000}

that timestamp is int64 or uint64 and nanosecond is int32 Protobuf-Type. Why a 64-bits integer be serialized as String type? Is there any JsonOptions was discussed to support 64-bits integer to JSON integer conversion?

@thomasvl
Copy link
Contributor

thomasvl commented Feb 7, 2017

That's the spec for the protobuf json format: https://developers.google.com/protocol-buffers/docs/proto3#json

Someone will have to confirm, but I believe the reason is in javascript, some browser can't handle a full 64bit value as a number, so the only way to ensure they can work for those clients is to handle them as strings.

@david9991
Copy link
Author

@thomasvl Oh I see, this is a Javascript precision problem that mentioned in some article, thank you very much.

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

No branches or pull requests

2 participants