|
@@ -2,16 +2,16 @@ package test
|
|
|
|
|
|
|
|
import (
|
|
import (
|
|
|
"bytes"
|
|
"bytes"
|
|
|
- "encoding/json"
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
"github.com/stretchr/testify/require"
|
|
|
"testing"
|
|
"testing"
|
|
|
|
|
+ "github.com/json-iterator/go"
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
func Test_disallowUnknownFields(t *testing.T) {
|
|
func Test_disallowUnknownFields(t *testing.T) {
|
|
|
should := require.New(t)
|
|
should := require.New(t)
|
|
|
type TestObject struct{}
|
|
type TestObject struct{}
|
|
|
var obj TestObject
|
|
var obj TestObject
|
|
|
- decoder := json.NewDecoder(bytes.NewBufferString(`{"field1":100}`))
|
|
|
|
|
|
|
+ decoder := jsoniter.NewDecoder(bytes.NewBufferString(`{"field1":100}`))
|
|
|
decoder.DisallowUnknownFields()
|
|
decoder.DisallowUnknownFields()
|
|
|
should.Error(decoder.Decode(&obj))
|
|
should.Error(decoder.Decode(&obj))
|
|
|
}
|
|
}
|