fix: #3449 accept slice parameter as json.RawMessage for http request (#3452)

This commit is contained in:
wln32
2024-04-07 14:09:52 +08:00
committed by GitHub
parent 911f1cb1de
commit 83ba887df7
3 changed files with 102 additions and 1 deletions

View File

@ -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 {

View File

@ -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 {