mirror of
https://github.com/json-iterator/go.git
synced 2025-04-20 11:28:49 +02:00
18 lines
380 B
Go
18 lines
380 B
Go
|
package test
|
||
|
|
||
|
import (
|
||
|
"bytes"
|
||
|
"github.com/json-iterator/go"
|
||
|
"github.com/stretchr/testify/require"
|
||
|
"testing"
|
||
|
)
|
||
|
|
||
|
func Test_disallowUnknownFields(t *testing.T) {
|
||
|
should := require.New(t)
|
||
|
type TestObject struct{}
|
||
|
var obj TestObject
|
||
|
decoder := jsoniter.NewDecoder(bytes.NewBufferString(`{"field1":100}`))
|
||
|
decoder.DisallowUnknownFields()
|
||
|
should.Error(decoder.Decode(&obj))
|
||
|
}
|