Open ngicks opened 1 year ago
Oh it doesn't also align its behavior to std where ,string
option should not apply to null
or non-applicable type.
The former one is poorly documented. The latter is explicit.
type Quote struct {
Foo int `json:",string"`
Bar *int `json:",string"`
Baz Sub `json:",string"`
}
type Sub struct {
Qux string
}
func TestQuote_behavior(t *testing.T) {
v := Quote{
Foo: 10,
Bar: nil,
Baz: Sub{
Qux: "qux",
},
}
binOrg, err := json.Marshal(v)
if err != nil {
panic(err)
}
binMimic, err := jsoniter.Marshal(v)
if err != nil {
panic(err)
}
str1, str2 := string(binOrg), string(binMimic)
if str1 != str2 {
t.Errorf("not same, type = %T. org = %s, jsoniter = %s\n", v, str1, str2)
}
}
--- FAIL: TestQuote_behavior (0.00s)
string_opt_test.go:40: not same, type = testjsoniter_test.Quote. org = {"Foo":"10","Bar":null,"Baz":{"Qux":"qux"}}, jsoniter = {"Foo":"10","Bar":"null","Baz":"{"Qux":"qux"}"}
encoding/json
prevents this by these linesvisited
map by quick read through of source code.encoding/json
describes this behavior in its source code but is not documented.Searching through issues with "recursive" does not give me any similar issues. Are these behaviors intentionally dropped?
I've uploaded test code here.
https://github.com/ngicks/test-jsoniter
This gives result of