1
0
mirror of https://github.com/json-iterator/go.git synced 2025-12-20 23:30:38 +02:00

implement #230 DisallowUnknownFields option added

This commit is contained in:
Tao Wen
2018-02-05 23:03:53 +08:00
parent 7990317be5
commit 71f74dc71e
6 changed files with 60 additions and 16 deletions

17
api_tests/decoder_test.go Normal file
View File

@@ -0,0 +1,17 @@
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))
}