mirror of
https://github.com/gin-gonic/gin.git
synced 2025-10-22 09:34:33 +08:00
Update json.go
Current it is not possible to tell the default JSON binder to use DisallowUnknownFields (supported by jsoniter and default Go json decoder). Use package variable EnableDecoderKnownFieldsOnly as a switch.
This commit is contained in:
parent
d6b2c13b18
commit
e7f3a0ebbe
@ -17,6 +17,10 @@ import (
|
||||
// interface{} as a Number instead of as a float64.
|
||||
var EnableDecoderUseNumber = false
|
||||
|
||||
// EnableDecoderKnownFieldsOnly is used to toggle DisallowUnknownFields
|
||||
// which is disabled by default
|
||||
var EnableDecoderKnownFieldsOnly = false
|
||||
|
||||
type jsonBinding struct{}
|
||||
|
||||
func (jsonBinding) Name() string {
|
||||
@ -36,6 +40,9 @@ func decodeJSON(r io.Reader, obj interface{}) error {
|
||||
if EnableDecoderUseNumber {
|
||||
decoder.UseNumber()
|
||||
}
|
||||
if EnableDecoderKnownFieldsOnly {
|
||||
decoder.DisallowUnknownFields()
|
||||
}
|
||||
if err := decoder.Decode(obj); err != nil {
|
||||
return err
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user