func TestIssueStringTagMismatchSkip_decode(t *testing.T) {
// match
eo := []byte(`{"D":"20","E":1}`)
et := reflect.TypeOf(IssueStringTag{})
testUnmarshal(t, eo, et, true)
// mismatch
eo = []byte(`{"D":11,"E":1}`)
testUnmarshal(t, eo, et, true)
// null
eo = []byte(`{"D":null,"E":1}`)
testUnmarshal(t, eo, et, true)
}
func testUnmarshal(t *testing.T, eo []byte, rt reflect.Type, checkobj bool) {
obj := reflect.New(rt).Interface()
println(string(eo))
println("sonic")
es := sonic.Unmarshal(eo, obj)
obj2 := reflect.New(rt).Interface()
println("std")
ee := json.Unmarshal(eo, obj2)
assert.Equal(t, ee ==nil, es == nil, es)
if checkobj {
assert.Equal(t, obj2, obj)
}
fmt.Printf("std: %v, obj: %#v", ee, obj2)
fmt.Printf("sonic error: %v, obj: %#v", es, obj)
}
type IssueStringTag struct {
D int form:"D" json:"D,string" query:"D"
E int
}
Reproducible codes
codes
func testUnmarshal(t *testing.T, eo []byte, rt reflect.Type, checkobj bool) { obj := reflect.New(rt).Interface() println(string(eo)) println("sonic") es := sonic.Unmarshal(eo, obj) obj2 := reflect.New(rt).Interface() println("std") ee := json.Unmarshal(eo, obj2) assert.Equal(t, ee ==nil, es == nil, es) if checkobj { assert.Equal(t, obj2, obj) } fmt.Printf("std: %v, obj: %#v", ee, obj2) fmt.Printf("sonic error: %v, obj: %#v", es, obj) }
type IssueStringTag struct { D int
form:"D" json:"D,string" query:"D"
E int }