diff --git a/util/gconv/gconv_map.go b/util/gconv/gconv_map.go index 1fc0716bf..7534f9175 100644 --- a/util/gconv/gconv_map.go +++ b/util/gconv/gconv_map.go @@ -407,7 +407,7 @@ func doMapConvertForMapOrStructValue(in doMapConvertForMapOrStructValueInput) in array[arrayIndex] = doMapConvertForMapOrStructValue( doMapConvertForMapOrStructValueInput{ IsRoot: false, - Value: rvAttrField.Index(arrayIndex), + Value: rvAttrField.Index(arrayIndex).Interface(), RecursiveType: in.RecursiveType, RecursiveOption: in.RecursiveType == recursiveTypeTrue, Tags: in.Tags, @@ -463,7 +463,7 @@ func doMapConvertForMapOrStructValue(in doMapConvertForMapOrStructValueInput) in for i := 0; i < length; i++ { array[i] = doMapConvertForMapOrStructValue(doMapConvertForMapOrStructValueInput{ IsRoot: false, - Value: reflectValue.Index(i), + Value: reflectValue.Index(i).Interface(), RecursiveType: in.RecursiveType, RecursiveOption: in.RecursiveType == recursiveTypeTrue, Tags: in.Tags, diff --git a/util/gconv/gconv_z_unit_issue_test.go b/util/gconv/gconv_z_unit_issue_test.go index c4e6249a5..4033a2dee 100644 --- a/util/gconv/gconv_z_unit_issue_test.go +++ b/util/gconv/gconv_z_unit_issue_test.go @@ -223,3 +223,43 @@ func Test_Issue2381(t *testing.T) { t.Assert(a1.Flag.String(), a2.Flag.String()) }) } + +// https://github.com/gogf/gf/issues/2391 +func Test_Issue2391(t *testing.T) { + gtest.C(t, func(t *gtest.T) { + type Inherit struct { + Ids []int + Ids2 []int64 + Flag *gjson.Json + Title string + } + + type Test1 struct { + Inherit + } + type Test2 struct { + Inherit + } + + var ( + a1 Test1 + a2 Test2 + ) + + a1 = Test1{ + Inherit{ + Ids: []int{1, 2, 3}, + Ids2: []int64{4, 5, 6}, + Flag: gjson.New("[\"1\", \"2\"]"), + Title: "测试", + }, + } + + err := gconv.Scan(a1, &a2) + t.AssertNil(err) + t.Assert(a1.Ids, a2.Ids) + t.Assert(a1.Ids2, a2.Ids2) + t.Assert(a1.Title, a2.Title) + t.Assert(a1.Flag.String(), a2.Flag.String()) + }) +}