...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package issue_test
16
17 import (
18 `encoding/json`
19 `testing`
20
21 `github.com/bytedance/sonic`
22 `github.com/stretchr/testify/require`
23 )
24
25 type OmitEmptyInterface struct {
26 ErrCode int32 `json:"code"`
27 Data interface{} `json:"data,omitempty"`
28 }
29
30 func TestOmitEmptyInterface(t *testing.T) {
31
32 var data *string
33 resp := &OmitEmptyInterface{
34 ErrCode: 123,
35 Data: data,
36 }
37 eout, eerr := json.Marshal(resp)
38 sout, serr := sonic.Marshal(resp)
39 require.Equal(t, eerr == nil, serr == nil)
40 require.Equal(t, string(eout), string(sout))
41
42
43 resp = &OmitEmptyInterface{
44 ErrCode: 123,
45 Data: nil,
46 }
47 eout, eerr = json.Marshal(resp)
48 sout, serr = sonic.Marshal(resp)
49 require.Equal(t, eerr == nil, serr == nil)
50 require.Equal(t, string(eout), string(sout))
51 }
View as plain text