Skip to content

JSON unmarshaler returns UnknownFieldError error #250

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

Conversation

atombender
Copy link

This makes the JSON unmarshaler return a new error struct, UnknownFieldError, for unknown fields, when AllowUnknownFields is false. This is necessary in order for callers to be able to hide Go internals in APIs. Previously, the error of Unmarshal would be an error string such as:

unknown field "glorp" in proto.Mutation

This leaks the type proto.Mutation to clients, which should not need to see such internals when they are consuming a pure-JSON HTTP API.

There are other instances of fmt.Errorf being used, but this is the main one that leaks.

@atombender
Copy link
Author

Hold on, I'll add a test for this struct.

@atombender atombender force-pushed the struct_for_unknown_json_fields branch from 4e1db73 to ac139e1 Compare November 11, 2016 19:27
@dsnet dsnet added the jsonpb label May 19, 2017
@dsnet
Copy link
Member

dsnet commented Mar 9, 2018

Before adding API to distinguish between different json errors, there should first be an issue that discusses what the use-case for this even should be. After that, we can figure out what the right API is. A new error type is not necessarily the API we would want to go with.

Feel free to open an issue justifying the ability to distinguish an unknown field error.

@atombender
Copy link
Author

I created an issue. Hopefully it won't take another year for this to be resolved.

@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.

2 participants