You've already forked json-iterator
mirror of
https://github.com/json-iterator/go.git
synced 2025-11-26 22:40:13 +02:00
use reflect2 for json.Marshaler
This commit is contained in:
@@ -10,6 +10,7 @@ func init() {
|
||||
var pString = func(val string) *string {
|
||||
return &val
|
||||
}
|
||||
epoch := time.Unix(0, 0)
|
||||
unmarshalCases = append(unmarshalCases, unmarshalCase{
|
||||
ptr: (*struct {
|
||||
Field interface{}
|
||||
@@ -83,13 +84,9 @@ func init() {
|
||||
struct {
|
||||
F *float64
|
||||
}{},
|
||||
// TODO: fix this
|
||||
//struct {
|
||||
// *time.Time
|
||||
//}{},
|
||||
struct {
|
||||
*time.Time
|
||||
}{&time.Time{}},
|
||||
}{&epoch},
|
||||
struct {
|
||||
*StructVarious
|
||||
}{&StructVarious{}},
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"encoding/json"
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/json-iterator/go"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type unmarshalCase struct {
|
||||
@@ -19,6 +20,10 @@ var marshalCases = []interface{}{
|
||||
nil,
|
||||
}
|
||||
|
||||
type selectedMarshalCase struct {
|
||||
marshalCase interface{}
|
||||
}
|
||||
|
||||
func Test_unmarshal(t *testing.T) {
|
||||
should := require.New(t)
|
||||
for _, testCase := range unmarshalCases {
|
||||
@@ -35,9 +40,16 @@ func Test_unmarshal(t *testing.T) {
|
||||
|
||||
func Test_marshal(t *testing.T) {
|
||||
for _, testCase := range marshalCases {
|
||||
selectedMarshalCase, found := testCase.(selectedMarshalCase)
|
||||
if found {
|
||||
marshalCases = []interface{}{selectedMarshalCase.marshalCase}
|
||||
break
|
||||
}
|
||||
}
|
||||
for i, testCase := range marshalCases {
|
||||
var name string
|
||||
if testCase != nil {
|
||||
name = reflect.TypeOf(testCase).String()
|
||||
name = fmt.Sprintf("[%v]%v/%s", i, testCase, reflect.TypeOf(testCase).String())
|
||||
}
|
||||
t.Run(name, func(t *testing.T) {
|
||||
should := require.New(t)
|
||||
|
||||
Reference in New Issue
Block a user