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

Configurable AllowUnknownFields in jsonpb? #448

Closed
lantame opened this issue Aug 30, 2017 · 3 comments
Closed

Configurable AllowUnknownFields in jsonpb? #448

lantame opened this issue Aug 30, 2017 · 3 comments

Comments

@lantame
Copy link
Contributor

lantame commented Aug 30, 2017

Now unknown object fields are silently dropped.
If I want to handle such cases, I have to provide a custom unmarshaller (likely by copying all unmarshalling stuff from runtime/marshal_jsonpb.go and changing AllowUnknownFields to false). Isn't it better to make this parameter configurable?

P.S. There will probably be some API change:
type JSONPb jsonpb.Marshaler will likely change to
type JSONPb struct{...}
Which will require existing code modification.

@buchanae
Copy link

Does WithMarshalerOption solve your issue?

We use this to configure a jsonpb.Marshaler the way we like:

customMar := jsonpb.Marshaler{
	Indent: "  ",
        EmitDefaults: true,
}
mar := runtime.JSONPb(customMar)
rpcMux := runtime.NewServeMux(runtime.WithMarshalerOption("*/*", &mar))

@buchanae
Copy link

buchanae commented Dec 5, 2017

Oh, no, it does not solve your issue. The offending line is here:
https://github.com/grpc-ecosystem/grpc-gateway/blob/master/runtime/marshal_jsonpb.go#L114

That unmarhsaler should be configurable. Maybe run.time.JSONPb.SetUnmarshaler() should be added?

@racevedoo
Copy link

@buchanae @lantame any update on this? I'm having the exact same problem

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