You've already forked json-iterator
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:
17
api_tests/decoder_test.go
Normal file
17
api_tests/decoder_test.go
Normal 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))
|
||||
}
|
||||
Reference in New Issue
Block a user