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

Ruby JSON deserialization fails for Int64Value and UInt64Value #6498

Closed
martinxsliu opened this issue Aug 13, 2019 · 3 comments
Closed

Ruby JSON deserialization fails for Int64Value and UInt64Value #6498

martinxsliu opened this issue Aug 13, 2019 · 3 comments
Assignees
Labels

Comments

@martinxsliu
Copy link

martinxsliu commented Aug 13, 2019

What version of protobuf and what language are you using?
Version: 3.9.1
Language: Ruby

What operating system (Linux, Windows, ...) and version?
OS X

What runtime / compiler are you using (e.g., python version or gcc version)
ruby 2.5.5p157 (2019-03-15 revision 67260) [x86_64-darwin18]

What did you do?
Decode a JSON encoded message with an Int64Value or an UInt64Value field. The canonical JSON encoding for wrapper types is the same as the wrapped primitive, which in the case of int64 and uint64 is a string.

> MyMessage.decode_json('{"int64value": "123"}')

What did you expect to see
A decoded protobuf object with the int64value field set:

<MyMessage: int64value: <Google::Protobuf::Int64Value: value: 123>>

What did you see instead?

Google::Protobuf::ParseError: Error occurred during parsing: String specified for bool or submessage field: int64value

Anything else we should know about your project / environment

  1. Decoding will work if the JSON value is a number instead of a string. e.g.
> MyMessage.decode_json('{"int64value": 123}')
  1. Decoding a JSON string where the wrappers are represented as a nested object instead of a nullable primitive works. (See: Ruby decode_json not handling timestamps and int64 per JSON Mapping spec #3013) e.g.
> MyMessage.decode_json('{"int64value": {"value": "123"}}')
  1. Decoding Int32Value and UInt32Value works because 32bit ints' JSON representations are numbers.
@carsol
Copy link

carsol commented Oct 18, 2019

Hello! 👋
I'm having this issue also. Has there been progress on this?

@vitorrd
Copy link

vitorrd commented Dec 18, 2020

Hello.

This issue is still ongoing. Protobuf fails to decode large numbers, which in JSON are encoded as strings, back into numbers. This is a rather serious problem as languages like Ruby make extensive use of non-JSON-compliant numbers.

Thanks in advance.

@haberman
Copy link
Member

This should be fixed by #8184, which is part of the v3.15.0-rc1 pre-release.

Please try it out and let us know if it doesn't work for you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants