mirror of
https://gitee.com/johng/gf
synced 2026-06-07 02:12:11 +08:00
improve gconv.StructDeep
This commit is contained in:
@ -69,3 +69,31 @@ func Test_Load_New_CustomStruct(t *testing.T) {
|
||||
t.Assert(s == `{"Id":1,"Name":"john"}` || s == `{"Name":"john","Id":1}`, true)
|
||||
})
|
||||
}
|
||||
|
||||
func Test_Load_New_HierarchicalStruct(t *testing.T) {
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
type Me struct {
|
||||
Name string `json:"name"`
|
||||
Score int `json:"score"`
|
||||
Children []Me `json:"children"`
|
||||
}
|
||||
me := Me{
|
||||
Name: "john",
|
||||
Score: 100,
|
||||
Children: []Me{
|
||||
{
|
||||
Name: "Bean",
|
||||
Score: 99,
|
||||
},
|
||||
{
|
||||
Name: "Sam",
|
||||
Score: 98,
|
||||
},
|
||||
},
|
||||
}
|
||||
j := gjson.New(me)
|
||||
t.Assert(j.Remove("children.0.score"), nil)
|
||||
t.Assert(j.Remove("children.1.score"), nil)
|
||||
t.Assert(j.MustToJsonString(), `{"children":[{"children":null,"name":"Bean"},{"children":null,"name":"Sam"}],"name":"john","score":100}`)
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user