mirror of
https://gitee.com/johng/gf
synced 2026-06-06 16:21:40 +08:00
fix issue struct attribute converting when has no json name but with omitempty tag (#2486)
This commit is contained in:
@ -332,6 +332,9 @@ func doMapConvertForMapOrStructValue(in doMapConvertForMapOrStructValueInput) in
|
||||
mapKey = strings.TrimSpace(array[0])
|
||||
}
|
||||
}
|
||||
if mapKey == "" {
|
||||
mapKey = fieldName
|
||||
}
|
||||
}
|
||||
if in.RecursiveOption || rtField.Anonymous {
|
||||
// Do map converting recursively.
|
||||
|
||||
@ -606,3 +606,17 @@ func TestMapsDeep(t *testing.T) {
|
||||
t.Assert(list[1]["id"], 200)
|
||||
})
|
||||
}
|
||||
|
||||
func TestMapWithJsonOmitEmpty(t *testing.T) {
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
type S struct {
|
||||
Key string `json:",omitempty"`
|
||||
Value interface{} `json:",omitempty"`
|
||||
}
|
||||
s := S{
|
||||
Key: "",
|
||||
Value: 1,
|
||||
}
|
||||
t.Assert(gconv.Map(s), g.Map{"Value": 1})
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user