-
Notifications
You must be signed in to change notification settings - Fork 455
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
Missing fields from JSON serialization #606
Comments
This is standard protobuf behavior. Proto3 compresses the output by omitting any field that has a default value. This applies to both the binary protobuf encoding and to JSON encoding. From https://developers.google.com/protocol-buffers/docs/proto3#json
|
@tbkka - does it mean that if change the default value later and the deserialization of an old serialized data will produce wrong results? |
In proto3 syntax, the only possible default values are the zero values, so they can't really be changed. In proto2 syntax, you can state explicit default values (non zero). But since any value that is explicitly set is sent over the wire (JSON, binary, etc.), the conditions are a little different. The proto2 guide talks about changing defaults in the section on updating a proto definition. |
ok, thank you for the clarification |
@thomasvl The specification seems to mention that implementations can allow default values to be encoded in the JSON as an option. Would it be possible to have it added as an option to this function call:
Or specifically a property here:
If the answer is yes but limited resources, I'd be happy to try make a PR. |
See #861 |
If enum is set to its default value it seems that the field is missing from the JSON.
For example:
If the code is:
then the output is wrong and the field is missing:
{}
However if change the value of
e
to$0.e = .secondValue
then the output is correct:{"e":"SECOND_VALUE"}
The text was updated successfully, but these errors were encountered: