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

How to set JSON options to emit fields with default values in proto3 #6035

Closed
ganl opened this issue Apr 13, 2019 · 6 comments
Closed

How to set JSON options to emit fields with default values in proto3 #6035

ganl opened this issue Apr 13, 2019 · 6 comments
Assignees

Comments

@ganl
Copy link

ganl commented Apr 13, 2019

PHP

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

JSON options
A proto3 JSON implementation may provide the following options:

Emit fields with default values: Fields with default values are omitted by default in proto3 JSON output. An implementation may provide an option to override this behavior and output fields with their default values.

how to set ?like:EmitDefaults or defaults_json

\Google\Protobuf\Internal\Message::existField 
……
            return $values !== $this->defaultValue($field);

Fields with default values are always omitted

@ganl
Copy link
Author

ganl commented Apr 14, 2019

@TeBoring

@TeBoring TeBoring self-assigned this Apr 26, 2019
@TeBoring TeBoring added the php label Apr 26, 2019
@TeBoring
Copy link
Contributor

We haven't implemented that option yet. Would you like to contribute a PR? Thanks!

@csuntrane
Copy link

Any idea when this might be implemented. It seems proto2 doesn't have this issue.

@panol
Copy link

panol commented Jun 1, 2021

plus one

@deannagarcia
Copy link
Member

While this is a reasonable request, the protobuf team will not be prioritizing this in the near future. If you send us a PR to add it, we would love to help get it merged!

@maciek-szn
Copy link

Well, this is great. Google's GTFS-RT specification requires field incrementality in the output file, with its default value (FULL_DATASET). Google's Protobuf compiler cuts off the default values 🤷‍♂️

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

No branches or pull requests

7 participants