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
Hi @rsc @adg
I've noticed that encoding/json doesn't raise an error if any field is not present in the body payload.
Example:
type DecodeRequest struct{ ID int `json:"id"` Name string `json:"name"` } func DecodeRequest(g *gin.Context) error{ var decodeRq DecodeRequest dec := json.NewDecoder(g.Request.Body) //Body payload : {"id" : 123} dec.DisallowUnknownFields() err := dec.Decode(&decodeRq) fmt.Println(err) -> nil }
Ideally, this function should give an error like missingfield name.
missingfield name
DisallowUnknownFields just take care of extra fields but not the missing field.
DisallowUnknownFields
Golang version: 1.15.6
Let me know if I've missed anything to fix it?
The text was updated successfully, but these errors were encountered:
see also #17163 #19858
Sorry, something went wrong.
@seankhliao Thanks for the reply. I see that this proposal is already on hold. When can we expect this feature in the next release?
Thanks
Yes, this is a duplicate of #19858. We can't provide timeline estimates, sorry - taking a look at all JSON proposals is a big chunk of ongoing work.
No branches or pull requests
Hi @rsc @adg
I've noticed that encoding/json doesn't raise an error if any field is not present in the body payload.
Example:
Ideally, this function should give an error like
missingfield name
.DisallowUnknownFields
just take care of extra fields but not the missing field.Golang version: 1.15.6
Let me know if I've missed anything to fix it?
The text was updated successfully, but these errors were encountered: