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 implement emit default to response or have flag option #92

Open
zengzhengrong opened this issue Jun 19, 2020 · 2 comments
Open

Comments

@zengzhengrong
Copy link

https://stackoverflow.com/questions/34716238/golang-protobuf-remove-omitempty-tag-from-generated-json-tags
The zero vaule of field be omited, I remove omitempty flag in struct, but it do not work in reponse

@utrack
Copy link
Owner

utrack commented Jun 19, 2020

You can override global marshaler using httpruntime:

https://github.com/utrack/clay/blob/master/transport/httpruntime/mjson.go#L13

httpruntime.OverrideMarshaler("application/json",httpruntime.MarshalerPbJSON{
	Marshaler:       &runtime.JSONPb{EmitDefaults: true},
	Unmarshaler:     &runtime.JSONPb{},
	GogoMarshaler:   &gogojsonpb.Marshaler{EmitDefaults:true},
	GogoUnmarshaler: &gogojsonpb.Unmarshaler{},
})

@wish-master
Copy link
Contributor

I will prepare #84
After closing that issue you'll be able to configure this param

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

No branches or pull requests

3 participants