Skip to content

Commit

Permalink
fix issue in gconv.MapDeep
Browse files Browse the repository at this point in the history
  • Loading branch information
gqcn committed Jun 5, 2021
1 parent 8aa7f08 commit eb723e4
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
2 changes: 1 addition & 1 deletion util/gconv/gconv_map.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
54 changes: 54 additions & 0 deletions util/gconv/gconv_z_unit_map_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down

0 comments on commit eb723e4

Please sign in to comment.