mirror of
https://gitee.com/johng/gf
synced 2026-06-06 16:21:40 +08:00
fix issue #1568
This commit is contained in:
@ -217,23 +217,25 @@ func doMapConvertForMapOrStructValue(isRoot bool, value interface{}, recursive b
|
||||
return dataMap
|
||||
|
||||
case reflect.Struct:
|
||||
var dataMap = make(map[string]interface{})
|
||||
// Map converting interface check.
|
||||
if v, ok := value.(iMapStrAny); ok {
|
||||
m := v.MapStrAny()
|
||||
if recursive {
|
||||
for k, v := range m {
|
||||
m[k] = doMapConvertForMapOrStructValue(false, v, recursive, tags...)
|
||||
// Value copy, in case of concurrent safety.
|
||||
for mapK, mapV := range v.MapStrAny() {
|
||||
if recursive {
|
||||
dataMap[mapK] = doMapConvertForMapOrStructValue(false, mapV, recursive, tags...)
|
||||
} else {
|
||||
dataMap[mapK] = mapV
|
||||
}
|
||||
}
|
||||
return m
|
||||
return dataMap
|
||||
}
|
||||
// Using reflect for converting.
|
||||
var (
|
||||
rtField reflect.StructField
|
||||
rvField reflect.Value
|
||||
dataMap = make(map[string]interface{}) // result map.
|
||||
reflectType = reflectValue.Type() // attribute value type.
|
||||
mapKey = "" // mapKey may be the tag name or the struct attribute name.
|
||||
reflectType = reflectValue.Type() // attribute value type.
|
||||
mapKey = "" // mapKey may be the tag name or the struct attribute name.
|
||||
)
|
||||
for i := 0; i < reflectValue.NumField(); i++ {
|
||||
rtField = reflectType.Field(i)
|
||||
@ -319,8 +321,10 @@ func doMapConvertForMapOrStructValue(isRoot bool, value interface{}, recursive b
|
||||
break
|
||||
}
|
||||
array := make([]interface{}, length)
|
||||
for i := 0; i < length; i++ {
|
||||
array[i] = doMapConvertForMapOrStructValue(false, rvAttrField.Index(i), recursive, tags...)
|
||||
for arrayIndex := 0; arrayIndex < length; arrayIndex++ {
|
||||
array[arrayIndex] = doMapConvertForMapOrStructValue(
|
||||
false, rvAttrField.Index(arrayIndex), recursive, tags...,
|
||||
)
|
||||
}
|
||||
dataMap[mapKey] = array
|
||||
case reflect.Map:
|
||||
|
||||
Reference in New Issue
Block a user