Open antonsacred opened 1 year ago
Case 1
type Structure struct { Id int `json:"id"` *Structure } func TestIssueWithInlineStruct(t *testing.T) { obj := Structure{ Id: 99, } b, err := json.Marshal(obj) assertErr(t, err) assertEq(t, "key a", `{"id":99,null}`, string(b)) // compare with standard library b, err = stdjson.Marshal(obj) assertErr(t, err) assertEq(t, "key b", `{"id":99}`, string(b)) }
Case 2
type AlternativeStructure struct { Id int `json:"id"` *Structure } type Structure struct { Id int `json:"id"` Alternative AlternativeStructure `json:"alternative"` } func TestIssueWithInlineStruct(t *testing.T) { obj := Structure{ Id: 99, Alternative: AlternativeStructure{Id: 123}, } b, err := json.Marshal(obj) assertErr(t, err) assertEq(t, "key a", `{"id":99,"alternative":{"id":123,null}}`, string(b)) // compare with standard library b, err = stdjson.Marshal(obj) assertErr(t, err) assertEq(t, "key b", `{"id":99,"alternative":{"id":123}}`, string(b)) }
When structure in embedded to itself go-json produce invalid json {"id":123,null}
go-json
{"id":123,null}
Case 1
Case 2
When structure in embedded to itself
go-json
produce invalid json{"id":123,null}