-
Notifications
You must be signed in to change notification settings - Fork 15.6k
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
ProtoToJsonString : int64 is converted to string even when jstype=JSON_NUMBER #3423
Comments
That behavior (int64 field serialized as string JSON) cannot be changed. There is no plan to add an option for that because a plain int64 value is not exchangeable between different JSON implementations. You either need to make the receiving side accept string for int64, or change the field type to int32 or double. |
I made the change in the protobuf library to support that. |
jstype is a legacy option for a different purpose. It's specific to Javascript implementation and does not affect other languages (like MessageToJsonString in C++) at all. |
Ok. My only reference is the comment/todo written in google/protobuf/descriptor.proto. |
The comment in descriptor.proto seems to clearly say it is only for JavaScript. If there is a misleading comment, please let us know. |
I want the int64 field in one of the proto message as Integer only.
I understand that the default behaviour is to render it as string.
In my case I need it to be rendered as Integer while converting to JsonString.
From the google/protobuf/descriptor.proto specification, I see that jstype can be used.
Even after using [jstype=JS_NUMBER] for my int64 field, i am still getting the string in my proto to Json converison.
protoc version details-
vivek@velankar:~/main$ protoc --version
libprotoc 3.0.0
Verified using the example from the examples directory. I changed the following in proto file-
int64 id = 2 [jstype = JS_NUMBER] ; // Unique ID number for this person.
I added the MessageToJsonString call in the list_people.cc to verify
Proto:
Person ID: 1234
Name: vvvvv
JSON:
string id {"name":"vvvvv","id":"1234"}
I did try to fix it myself by changing RenderInt64 which makes json print int64 as integers unconditionally.
But we should have the option to choose this behaviour using jstype option as mentioned in the documentation.
Let me know if anything else required from my side.
Thanks
The text was updated successfully, but these errors were encountered: