Skip to content

add no_omitempty option to remote omitempty label from generated struct #684

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
wants to merge 1 commit into from

Conversation

sparkthu
Copy link

@cybrcodr
Copy link
Contributor

cybrcodr commented Aug 20, 2018

If this is meant for serializing a Protobuf type into JSON, one should use the package github.com/golang/protobuf/jsonpb instead of the standard encoding/json package. jsonpb.Marshaler has a field called EmitDefaults on whether to render or omit zero values.

@dsnet
Copy link
Member

dsnet commented Aug 20, 2018

Hi, thanks for the pull request, but we're going to decline. See my #682 (comment)

@dsnet dsnet closed this Aug 20, 2018
@sparkthu
Copy link
Author

@cybrcodr I tried to use jsonpb, but the name style is totally different with json. We already have lots of code using underline name style instead of camel which is generated by jsonpb.
If there is any method to use under line name style in jsonpb, please let me know. Thank you.

@cybrcodr
Copy link
Contributor

If you are using the original field name in the .proto file, you can set jsonpb.Marshaler.OrigName to true and that would use the original .proto field name which should be the same as the generated json tag name.

@sparkthu
Copy link
Author

@cybrcodr Awsome! I love it. Thank you so much

@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

Successfully merging this pull request may close these issues.

3 participants