mirror of
https://gitee.com/johng/gf.git
synced 2024-11-29 18:57:44 +08:00
fix issue struct attribute converting when has no json name but with omitempty tag (#2486)
This commit is contained in:
parent
e8088a6563
commit
13f6fb1929
@ -332,6 +332,9 @@ func doMapConvertForMapOrStructValue(in doMapConvertForMapOrStructValueInput) in
|
|||||||
mapKey = strings.TrimSpace(array[0])
|
mapKey = strings.TrimSpace(array[0])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if mapKey == "" {
|
||||||
|
mapKey = fieldName
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if in.RecursiveOption || rtField.Anonymous {
|
if in.RecursiveOption || rtField.Anonymous {
|
||||||
// Do map converting recursively.
|
// Do map converting recursively.
|
||||||
|
@ -606,3 +606,17 @@ func TestMapsDeep(t *testing.T) {
|
|||||||
t.Assert(list[1]["id"], 200)
|
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})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user