-
Notifications
You must be signed in to change notification settings - Fork 42
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
Option to disallow unknown fields when unmarshaling JSON #1368
Comments
There's a switch, |
Indeed, that looks like it does exactly what I need. |
Best way to see the per-code generator settings is as follows (substitute the version of the code generator you're using).
The
|
I would like the option to fail on unknown JSON fields when unmarshaling the generated model types.
Typically, one would do this in Go by substituting
json.Unmarshal(data, targetPtr)
with:However this doesn't work for the generated model types because they implement their own
UnmarshalJSON
method that use a switch statement for struct field names with no "default" case. For example, take this generated method:What I would like to see, when failure on unknown fields is desired, is a "default" case in the switch statement that returns an error.
This would likely require a new CLI switch, maybe initially for but not limited to Go code generation.
The text was updated successfully, but these errors were encountered: