mirror of
https://gitee.com/johng/gf
synced 2026-06-07 02:12:11 +08:00
This commit is contained in:
@ -7,9 +7,12 @@
|
||||
package gconv
|
||||
|
||||
import (
|
||||
"context"
|
||||
"reflect"
|
||||
"time"
|
||||
|
||||
"github.com/gogf/gf/v2/internal/intlog"
|
||||
"github.com/gogf/gf/v2/internal/json"
|
||||
"github.com/gogf/gf/v2/os/gtime"
|
||||
)
|
||||
|
||||
@ -270,7 +273,12 @@ func doConvert(in doConvertInput) (convertedValue interface{}) {
|
||||
return Maps(in.FromValue)
|
||||
|
||||
case "RawMessage", "json.RawMessage":
|
||||
return Bytes(in.FromValue)
|
||||
// issue 3449
|
||||
bytes, err := json.Marshal(in.FromValue)
|
||||
if err != nil {
|
||||
intlog.Errorf(context.TODO(), `%+v`, err)
|
||||
}
|
||||
return bytes
|
||||
|
||||
default:
|
||||
if in.ReferValue != nil {
|
||||
|
||||
@ -1303,6 +1303,33 @@ func Test_Struct_Issue1597(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
// https://github.com/gogf/gf/issues/3449
|
||||
func Test_Struct_Issue3449(t *testing.T) {
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
type S struct {
|
||||
A int
|
||||
B json.RawMessage
|
||||
}
|
||||
|
||||
jsonByte := []byte(`{
|
||||
"a":1,
|
||||
"b":[{
|
||||
"k1": "11",
|
||||
"k2": "12"
|
||||
},
|
||||
{
|
||||
"k1": "21",
|
||||
"k2": "22"
|
||||
}]}`)
|
||||
data, err := gjson.DecodeToJson(jsonByte)
|
||||
t.AssertNil(err)
|
||||
s := &S{}
|
||||
err = data.Scan(s)
|
||||
t.AssertNil(err)
|
||||
t.Assert(s.B, `[{"k1":"11","k2":"12"},{"k1":"21","k2":"22"}]`)
|
||||
})
|
||||
}
|
||||
|
||||
// https://github.com/gogf/gf/issues/2980
|
||||
func Test_Struct_Issue2980(t *testing.T) {
|
||||
type Post struct {
|
||||
|
||||
Reference in New Issue
Block a user