You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
ππ»ββοΈ Hello! I am starting with chi for my personal project. Is there some way to return an error if the received json request has an additional unexpected field?
Using the json.NewDecode(r.body) we can set dec.DisallowUnknownFields() and when we unmarshal the json object via Decode method we get that information error in the err value err := dec.Decode(&someStructType)
I am seeing the chi examples but I don't find examples about it.
Thanks for your assistance!
The text was updated successfully, but these errors were encountered:
You could override render.Decode function with your own.
Or, if #47 gets merged, you could override JSON decoder only.
Imho, for most REST API use cases, people don't want to be so strict on incoming JSON payload and error out on obsolete/deprecated field, which might be sent from an older version of a REST API client. So I'm not convinced we'll ever make it a feature. Or should we?
@VojtechVitek thanks for your suggestion about render.Decode I will check that option and learn a little more along the way. Interesting discussion in PR #47 about this topic.
Good point about not being too strict on incoming JSON payload, I didn't realize that aspect, I was thinking It was healthier reject the request but that could break the client.
ππ»ββοΈ Hello! I am starting with chi for my personal project. Is there some way to return an error if the received json request has an additional unexpected field?
Using the json.NewDecode(r.body) we can set
dec.DisallowUnknownFields()
and when we unmarshal the json object via Decode method we get that information error in the err valueerr := dec.Decode(&someStructType)
I am seeing the chi examples but I don't find examples about it.
Thanks for your assistance!
The text was updated successfully, but these errors were encountered: