diff --git a/util/gconv/gconv_map.go b/util/gconv/gconv_map.go index abab585cb..6685433b2 100644 --- a/util/gconv/gconv_map.go +++ b/util/gconv/gconv_map.go @@ -301,7 +301,7 @@ func doMapConvertForMapOrStructValue(isRoot bool, value interface{}, recursive b // It means this attribute field has desired tag. dataMap[mapKey] = doMapConvertForMapOrStructValue(false, rvAttrInterface, true, tags...) } else { - dataMap[mapKey] = doMapConvertForMapOrStructValue(false, rvAttrInterface, false, tags...) + dataMap[mapKey] = doMapConvertForMapOrStructValue(false, rvAttrInterface, recursive, tags...) } // The struct attribute is type of slice. diff --git a/util/gconv/gconv_z_unit_map_test.go b/util/gconv/gconv_z_unit_map_test.go index 55bca4f8d..f1676048c 100644 --- a/util/gconv/gconv_z_unit_map_test.go +++ b/util/gconv/gconv_z_unit_map_test.go @@ -317,6 +317,60 @@ func Test_MapDeep2(t *testing.T) { }) } +func Test_MapDeep3(t *testing.T) { + type Base struct { + Id int `c:"id"` + Date string `c:"date"` + } + type User struct { + UserBase Base `c:"base"` + Passport string `c:"passport"` + Password string `c:"password"` + Nickname string `c:"nickname"` + } + + gtest.C(t, func(t *gtest.T) { + user := &User{ + UserBase: Base{ + Id: 1, + Date: "2019-10-01", + }, + Passport: "john", + Password: "123456", + Nickname: "JohnGuo", + } + m := gconv.MapDeep(user) + t.Assert(m, g.Map{ + "base": g.Map{ + "id": user.UserBase.Id, + "date": user.UserBase.Date, + }, + "passport": user.Passport, + "password": user.Password, + "nickname": user.Nickname, + }) + }) + + gtest.C(t, func(t *gtest.T) { + user := &User{ + UserBase: Base{ + Id: 1, + Date: "2019-10-01", + }, + Passport: "john", + Password: "123456", + Nickname: "JohnGuo", + } + m := gconv.Map(user) + t.Assert(m, g.Map{ + "base": user.UserBase, + "passport": user.Passport, + "password": user.Password, + "nickname": user.Nickname, + }) + }) +} + func Test_MapDeepWithAttributeTag(t *testing.T) { type Ids struct { Id int `c:"id"`