Closed
Description
1. What version of Go
and system type/arch are you using?
go version go1.19.12 windows/amd64
2. What version of GoFrame
are you using?
v2.5.4
3. Can this issue be re-produced with the latest release?
Yes
4. What did you do?
package main
import (
"encoding/json"
"testing"
"github.com/gogf/gf/v2/test/gtest"
"github.com/gogf/gf/v2/util/gconv"
)
type tFF struct {
Val1 json.RawMessage `json:"val1"`
Val2 []json.RawMessage `json:"val2"`
Val3 map[string]json.RawMessage `json:"val3"`
}
func Test_gconv_RawMessage(t *testing.T) {
gtest.C(t, func(t *gtest.T) {
ff := &tFF{}
var tmp = map[string]any{
"val1": map[string]any{"hello": "world"},
"val2": []any{map[string]string{"hello": "world"}},
"val3": map[string]map[string]string{"val3": {"hello": "world"}},
}
err := gconv.Struct(tmp, ff)
t.AssertNil(err)
t.AssertNE(ff, nil)
t.Assert(ff.Val1, []byte(`{"hello":"world"}`))
t.AssertEQ(len(ff.Val2), 1)
t.Assert(ff.Val2[0], []byte(`{"hello":"world"}`))
t.AssertEQ(len(ff.Val3), 1)
t.Assert(ff.Val3["val3"], []byte(`{"hello":"world"}`))
})
}
5. What did you expect to see?
all test passed
6. What did you see instead?
gconv.Struct
prefer to use reflect.Type.Name()
to get type name rather than reflect.Type.String()
.
Lines 530 to 533 in 35e5f1f
reflect.Type(json.RawMessage).Name()
should be RawMessage
reflect.Type(json.RawMessage).String()
should be json.RawMessage
gf/util/gconv/gconv_convert.go
Lines 254 to 274 in 35e5f1f
so gconv_convert.go:272 case json.RawMessage
should be replaced by case RawMessage, json.RawMessage
Metadata
Metadata
Assignees
Labels
No labels
Activity