修复嵌套结构体 + 嵌套数组的BUG
This commit is contained in:
parent
9ef4123f38
commit
07fb74b68b
@ -189,7 +189,7 @@ func (b *builderImpl) Build() IDynamicStruct {
|
||||
} else {
|
||||
// 处理数组
|
||||
arrDeep := 0
|
||||
newParentNameArr := []string{}
|
||||
var newParentNameArr []string
|
||||
for i := len(parentNameArr) - 1; i >= 0; i-- {
|
||||
if parentNameArr[i] != ArraySplit {
|
||||
newParentNameArr = parentNameArr[:i+1]
|
||||
@ -206,18 +206,19 @@ func (b *builderImpl) Build() IDynamicStruct {
|
||||
val = reflect.New(reflect.SliceOf(reflect.TypeOf(val))).Interface()
|
||||
}
|
||||
// 解除指针引用
|
||||
val = reflect.ValueOf(val).Elem().Interface()
|
||||
// val = reflect.ValueOf(val).Elem().Interface()
|
||||
newParamIndex := strings.Join(newParentNameArr, ".")
|
||||
isTopIndex := len(newParentNameArr) == 1
|
||||
if isTopIndex {
|
||||
// 顶层结构, 数组类型不存在还有其他属性情况, 直接追加字段, 并移除嵌套表里的定义
|
||||
b.AddField(b.nestedStructTable[newParamIndex].Field, "", val, b.nestedStructTable[newParamIndex].Tag, false)
|
||||
delete(b.nestedStructTable, newParamIndex)
|
||||
// b.nestedStructTable[newParamIndex].Builder.AddField(b.nestedStructTable[newParamIndex].Field, "", val, b.nestedStructTable[newParamIndex].Tag, false)
|
||||
} else {
|
||||
// 非顶层结构, 再上探一级
|
||||
b.nestedStructTable[strings.Join(newParentNameArr[:len(newParentNameArr)-1], ".")].Builder.AddField(b.nestedStructTable[newParamIndex].Field, "", val, b.nestedStructTable[newParamIndex].Tag, false)
|
||||
}
|
||||
// 嵌套结构中删除数组字段
|
||||
delete(b.nestedStructTable, newParamIndex)
|
||||
} else {
|
||||
// 非数组
|
||||
// (非顶层) 父级结构存在, 将其追加到父级结构中即可, 向前看一步即为父级结构
|
||||
|
Loading…
x
Reference in New Issue
Block a user