decoder_test.go 380 B

1234567891011121314151617
  1. package test
  2. import (
  3. "bytes"
  4. "github.com/stretchr/testify/require"
  5. "testing"
  6. "github.com/json-iterator/go"
  7. )
  8. func Test_disallowUnknownFields(t *testing.T) {
  9. should := require.New(t)
  10. type TestObject struct{}
  11. var obj TestObject
  12. decoder := jsoniter.NewDecoder(bytes.NewBufferString(`{"field1":100}`))
  13. decoder.DisallowUnknownFields()
  14. should.Error(decoder.Decode(&obj))
  15. }