Skip to content

Commit

Permalink
fix: gjson encode to string expect inconformity(issue 2520) (gogf#2928)
Browse files Browse the repository at this point in the history
  • Loading branch information
wlynxg authored Sep 4, 2023
1 parent 000c7a9 commit eb11061
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
13 changes: 13 additions & 0 deletions encoding/gjson/gjson_z_unit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/gogf/gf/v2/container/gvar"
"github.com/gogf/gf/v2/encoding/gjson"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/gtime"
"github.com/gogf/gf/v2/test/gtest"
"github.com/gogf/gf/v2/util/gconv"
)
Expand Down Expand Up @@ -587,3 +588,15 @@ func Test_Issue1747(t *testing.T) {
t.Assert(j.Get("2"), `336371793314971759`)
})
}

// https://github.com/gogf/gf/issues/2520
func Test_Issue2520(t *testing.T) {
gtest.C(t, func(t *gtest.T) {
type test struct {
Unique *gvar.Var `json:"unique"`
}

t2 := test{Unique: gvar.New(gtime.Date())}
t.Assert(gjson.MustEncodeString(t2), gjson.New(t2).MustToJsonString())
})
}
4 changes: 3 additions & 1 deletion util/gconv/gconv_map.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,9 @@ func doMapConvertForMapOrStructValue(in doMapConvertForMapOrStructValueInput) in
dataMap[mapK] = mapV
}
}
return dataMap
if len(dataMap) > 0 {
return dataMap
}
}
// Using reflect for converting.
var (
Expand Down

0 comments on commit eb11061

Please sign in to comment.