mirror of
https://github.com/json-iterator/go.git
synced 2025-04-20 11:28:49 +02:00
check nil for interface{}
This commit is contained in:
parent
9dafbc667f
commit
ef3038593b
@ -599,7 +599,7 @@ type marshalerEncoder struct {
|
|||||||
|
|
||||||
func (encoder *marshalerEncoder) Encode(ptr unsafe.Pointer, stream *Stream) {
|
func (encoder *marshalerEncoder) Encode(ptr unsafe.Pointer, stream *Stream) {
|
||||||
obj := encoder.valType.UnsafeIndirect(ptr)
|
obj := encoder.valType.UnsafeIndirect(ptr)
|
||||||
if obj == nil {
|
if reflect2.IsNil(obj) {
|
||||||
stream.WriteNil()
|
stream.WriteNil()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -623,7 +623,7 @@ type textMarshalerEncoder struct {
|
|||||||
|
|
||||||
func (encoder *textMarshalerEncoder) Encode(ptr unsafe.Pointer, stream *Stream) {
|
func (encoder *textMarshalerEncoder) Encode(ptr unsafe.Pointer, stream *Stream) {
|
||||||
obj := encoder.valType.UnsafeIndirect(ptr)
|
obj := encoder.valType.UnsafeIndirect(ptr)
|
||||||
if obj == nil {
|
if reflect2.IsNil(obj) {
|
||||||
stream.WriteNil()
|
stream.WriteNil()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -251,8 +251,8 @@ func init() {
|
|||||||
})(nil),
|
})(nil),
|
||||||
(*struct {
|
(*struct {
|
||||||
TF1 struct {
|
TF1 struct {
|
||||||
F1 withTime
|
F2 int
|
||||||
F2 *withTime
|
F1 *withTime
|
||||||
}
|
}
|
||||||
})(nil),
|
})(nil),
|
||||||
(*DeeplyNested)(nil),
|
(*DeeplyNested)(nil),
|
||||||
|
@ -15,7 +15,18 @@ import (
|
|||||||
var testCases []interface{}
|
var testCases []interface{}
|
||||||
var asymmetricTestCases [][2]interface{}
|
var asymmetricTestCases [][2]interface{}
|
||||||
|
|
||||||
|
type selectedSymmetricCase struct {
|
||||||
|
testCase interface{}
|
||||||
|
}
|
||||||
|
|
||||||
func Test_symmetric(t *testing.T) {
|
func Test_symmetric(t *testing.T) {
|
||||||
|
for _, testCase := range testCases {
|
||||||
|
selectedSymmetricCase, found := testCase.(selectedSymmetricCase)
|
||||||
|
if found {
|
||||||
|
testCases = []interface{}{selectedSymmetricCase.testCase}
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
for _, testCase := range testCases {
|
for _, testCase := range testCases {
|
||||||
valType := reflect.TypeOf(testCase).Elem()
|
valType := reflect.TypeOf(testCase).Elem()
|
||||||
t.Run(valType.String(), func(t *testing.T) {
|
t.Run(valType.String(), func(t *testing.T) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user