mirror of https://github.com/goccy/go-json.git
fix: fixed a problem with NextField being wrong when combining structure embedding and omitempty (#442)
fix #441
This commit is contained in:
parent
4d199a4b2c
commit
5e6fe10846
|
@ -2694,3 +2694,19 @@ func TestIssue426(t *testing.T) {
|
|||
b, _ := json.Marshal(s)
|
||||
assertEq(t, "unexpected result", `{"I":null,"Val":"456"}`, string(b))
|
||||
}
|
||||
|
||||
func TestIssue441(t *testing.T) {
|
||||
type A struct {
|
||||
Y string `json:"y,omitempty"`
|
||||
}
|
||||
|
||||
type B struct {
|
||||
X *int `json:"x,omitempty"`
|
||||
A
|
||||
Z int `json:"z,omitempty"`
|
||||
}
|
||||
|
||||
b, err := json.Marshal(B{})
|
||||
assertErr(t, err)
|
||||
assertEq(t, "unexpected result", "{}", string(b))
|
||||
}
|
||||
|
|
|
@ -397,7 +397,7 @@ func (c *StructCode) lastFieldCode(field *StructFieldCode, firstField *Opcode) *
|
|||
func (c *StructCode) lastAnonymousFieldCode(firstField *Opcode) *Opcode {
|
||||
// firstField is special StructHead operation for anonymous structure.
|
||||
// So, StructHead's next operation is truly struct head operation.
|
||||
for firstField.Op == OpStructHead {
|
||||
for firstField.Op == OpStructHead || firstField.Op == OpStructField {
|
||||
firstField = firstField.Next
|
||||
}
|
||||
lastField := firstField
|
||||
|
|
Loading…
Reference in New Issue