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) {
|
||||
obj := encoder.valType.UnsafeIndirect(ptr)
|
||||
if obj == nil {
|
||||
if reflect2.IsNil(obj) {
|
||||
stream.WriteNil()
|
||||
return
|
||||
}
|
||||
@ -623,7 +623,7 @@ type textMarshalerEncoder struct {
|
||||
|
||||
func (encoder *textMarshalerEncoder) Encode(ptr unsafe.Pointer, stream *Stream) {
|
||||
obj := encoder.valType.UnsafeIndirect(ptr)
|
||||
if obj == nil {
|
||||
if reflect2.IsNil(obj) {
|
||||
stream.WriteNil()
|
||||
return
|
||||
}
|
||||
|
@ -251,8 +251,8 @@ func init() {
|
||||
})(nil),
|
||||
(*struct {
|
||||
TF1 struct {
|
||||
F1 withTime
|
||||
F2 *withTime
|
||||
F2 int
|
||||
F1 *withTime
|
||||
}
|
||||
})(nil),
|
||||
(*DeeplyNested)(nil),
|
||||
|
@ -15,7 +15,18 @@ import (
|
||||
var testCases []interface{}
|
||||
var asymmetricTestCases [][2]interface{}
|
||||
|
||||
type selectedSymmetricCase struct {
|
||||
testCase interface{}
|
||||
}
|
||||
|
||||
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 {
|
||||
valType := reflect.TypeOf(testCase).Elem()
|
||||
t.Run(valType.String(), func(t *testing.T) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user