proposal: encoding/json: add *json.Decoder to return type of DisallowUnknownFields #40443
For strict json parsing using encoding/json, one has to write the following quite often:
var mystruct Mystruct decoder := json.NewDecoder(request.Body) decoder.DisallowUnknownFields() err := decoder.Decode(&mystruct)
Instead, being able to chain these calls makes the API more pleasant to use:
var mystruct Mystruct err := json.NewDecoder(request.Body) .DisallowUnknownFields() .Decode(&mystruct)
It's also less error prone, as the decoder cannot be reused.
Technically this is a breaking change, since the DisallowUnknownFields might by passed as a function pointer, although I cannot imagine any use for that. Alternatively, We could add a
The text was updated successfully, but these errors were encountered: