mirror of
https://gitee.com/johng/gf
synced 2026-06-06 16:21:40 +08:00
fix issue in gconv.MapDeep
This commit is contained in:
@ -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.
|
||||
|
||||
@ -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"`
|
||||
|
||||
Reference in New Issue
Block a user