...
1
16
17 package issue_test
18
19 import (
20 . `github.com/bytedance/sonic`
21 `testing`
22 `encoding/json`
23
24 `github.com/stretchr/testify/require`
25 )
26
27 type (
28 Issue58ValueReceiver struct {}
29 Issue58PointerReceiver struct {}
30 )
31
32 func (_ Issue58ValueReceiver) MarshalJSON() ([]byte, error) { return []byte(`"value"`), nil }
33 func (_ *Issue58PointerReceiver) MarshalJSON() ([]byte, error) { return []byte(`"pointer"`), nil }
34
35 func TestIssue58_NilPointerOnValueMethod(t *testing.T) {
36 v := struct {
37 X *Issue58ValueReceiver
38 Y *Issue58PointerReceiver
39 }{}
40 buf, err := Marshal(v)
41 require.NoError(t, err)
42 require.Equal(t, []byte(`{"X":null,"Y":null}`), buf)
43 buf, err = json.Marshal(v)
44 require.NoError(t, err)
45 require.Equal(t, []byte(`{"X":null,"Y":null}`), buf)
46
47 }
48
View as plain text