mirror of https://github.com/goccy/go-json.git
pass all test cases
This commit is contained in:
parent
125177da35
commit
c9a4a47e1c
|
@ -690,7 +690,9 @@ func (c *StructFieldCode) ToAnonymousOpcode(ctx *compileContext, isFirstField, i
|
||||||
}
|
}
|
||||||
flags := c.flags()
|
flags := c.flags()
|
||||||
flags |= AnonymousHeadFlags
|
flags |= AnonymousHeadFlags
|
||||||
flags |= AnonymousKeyFlags
|
if c.isAnonymous {
|
||||||
|
flags |= AnonymousKeyFlags
|
||||||
|
}
|
||||||
field := &Opcode{
|
field := &Opcode{
|
||||||
Idx: opcodeOffset(ctx.ptrIndex),
|
Idx: opcodeOffset(ctx.ptrIndex),
|
||||||
Flags: flags,
|
Flags: flags,
|
||||||
|
@ -1304,13 +1306,41 @@ func getFieldMap(fields []*StructFieldCode) map[string][]*StructFieldCode {
|
||||||
fieldMap := map[string][]*StructFieldCode{}
|
fieldMap := map[string][]*StructFieldCode{}
|
||||||
for _, field := range fields {
|
for _, field := range fields {
|
||||||
if field.isAnonymous {
|
if field.isAnonymous {
|
||||||
structCode := field.getAnonymousStruct()
|
for k, v := range getAnonymousFieldMap(field) {
|
||||||
if structCode != nil && !structCode.isRecursive {
|
fieldMap[k] = append(fieldMap[k], v...)
|
||||||
for k, v := range getFieldMap(structCode.fields) {
|
|
||||||
fieldMap[k] = append(fieldMap[k], v...)
|
|
||||||
}
|
|
||||||
continue
|
|
||||||
}
|
}
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
fieldMap[field.key] = append(fieldMap[field.key], field)
|
||||||
|
}
|
||||||
|
return fieldMap
|
||||||
|
}
|
||||||
|
|
||||||
|
func getAnonymousFieldMap(field *StructFieldCode) map[string][]*StructFieldCode {
|
||||||
|
fieldMap := map[string][]*StructFieldCode{}
|
||||||
|
structCode := field.getAnonymousStruct()
|
||||||
|
if structCode == nil || structCode.isRecursive {
|
||||||
|
fieldMap[field.key] = append(fieldMap[field.key], field)
|
||||||
|
return fieldMap
|
||||||
|
}
|
||||||
|
for k, v := range getFieldMapFromAnonymousParent(structCode.fields) {
|
||||||
|
fieldMap[k] = append(fieldMap[k], v...)
|
||||||
|
}
|
||||||
|
return fieldMap
|
||||||
|
}
|
||||||
|
|
||||||
|
func getFieldMapFromAnonymousParent(fields []*StructFieldCode) map[string][]*StructFieldCode {
|
||||||
|
fieldMap := map[string][]*StructFieldCode{}
|
||||||
|
for _, field := range fields {
|
||||||
|
if field.isAnonymous {
|
||||||
|
for k, v := range getAnonymousFieldMap(field) {
|
||||||
|
// Do not handle tagged key when embedding more than once
|
||||||
|
for _, vv := range v {
|
||||||
|
vv.isTaggedKey = false
|
||||||
|
}
|
||||||
|
fieldMap[k] = append(fieldMap[k], v...)
|
||||||
|
}
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
fieldMap[field.key] = append(fieldMap[field.key], field)
|
fieldMap[field.key] = append(fieldMap[field.key], field)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue