Skip to content

Need an option to prevent add ",omit_empty" for json label #682

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

Closed
sparkthu opened this issue Aug 20, 2018 · 2 comments
Closed

Need an option to prevent add ",omit_empty" for json label #682

sparkthu opened this issue Aug 20, 2018 · 2 comments

Comments

@sparkthu
Copy link

When the json is used to communicate with browser, all field with omit_empty will cause lots of missing for keys.

@puellanivis
Copy link
Collaborator

Was not sure about how this aligned with the standards, so I looked it up:

An implementation may provide options to emit fields with default values in the JSON-encoded output.

https://developers.google.com/protocol-buffers/docs/proto3#json

It appears to be a valid option to do. But maybe the option name could be narrowed to be clear that it is json-specific: json_emit_default_values.

@dsnet
Copy link
Member

dsnet commented Aug 20, 2018

The generation of the json tag predates the finalization of the JSON<->Protobuf specification. When that spec was finalized, it became clear that the json tag alone could not be used to implement the specification (unless the encoding/json provides some advanced features). In retrospect, I wish we never generated the json tags.

That being said, adding a command-line option to remove this is not the right solution for several reasons:

I'm going to close this in favor of #52, which is the closest issue to being able to support this.

@dsnet dsnet closed this as completed Aug 20, 2018
@golang golang locked and limited conversation to collaborators Jun 26, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants