88 "encoding/binary"
99 "encoding/json" //nolint:depguard // this package wraps it
1010 "io"
11-
12- jsoniter "github.com/json-iterator/go"
1311)
1412
1513// Encoder represents an encoder for json
@@ -31,70 +29,7 @@ type Interface interface {
3129 Indent (dst * bytes.Buffer , src []byte , prefix , indent string ) error
3230}
3331
34- var (
35- DefaultJSONHandler = getDefaultJSONHandler ()
36-
37- _ Interface = StdJSON {}
38- _ Interface = JSONiter {}
39- )
40-
41- // StdJSON implements Interface via encoding/json
42- type StdJSON struct {}
43-
44- // Marshal implements Interface
45- func (StdJSON ) Marshal (v any ) ([]byte , error ) {
46- return json .Marshal (v )
47- }
48-
49- // Unmarshal implements Interface
50- func (StdJSON ) Unmarshal (data []byte , v any ) error {
51- return json .Unmarshal (data , v )
52- }
53-
54- // NewEncoder implements Interface
55- func (StdJSON ) NewEncoder (writer io.Writer ) Encoder {
56- return json .NewEncoder (writer )
57- }
58-
59- // NewDecoder implements Interface
60- func (StdJSON ) NewDecoder (reader io.Reader ) Decoder {
61- return json .NewDecoder (reader )
62- }
63-
64- // Indent implements Interface
65- func (StdJSON ) Indent (dst * bytes.Buffer , src []byte , prefix , indent string ) error {
66- return json .Indent (dst , src , prefix , indent )
67- }
68-
69- // JSONiter implements Interface via jsoniter
70- type JSONiter struct {
71- jsoniter.API
72- }
73-
74- // Marshal implements Interface
75- func (j JSONiter ) Marshal (v any ) ([]byte , error ) {
76- return j .API .Marshal (v )
77- }
78-
79- // Unmarshal implements Interface
80- func (j JSONiter ) Unmarshal (data []byte , v any ) error {
81- return j .API .Unmarshal (data , v )
82- }
83-
84- // NewEncoder implements Interface
85- func (j JSONiter ) NewEncoder (writer io.Writer ) Encoder {
86- return j .API .NewEncoder (writer )
87- }
88-
89- // NewDecoder implements Interface
90- func (j JSONiter ) NewDecoder (reader io.Reader ) Decoder {
91- return j .API .NewDecoder (reader )
92- }
93-
94- // Indent implements Interface, since jsoniter don't support Indent, just use encoding/json's
95- func (j JSONiter ) Indent (dst * bytes.Buffer , src []byte , prefix , indent string ) error {
96- return json .Indent (dst , src , prefix , indent )
97- }
32+ var DefaultJSONHandler = getDefaultJSONHandler ()
9833
9934// Marshal converts object as bytes
10035func Marshal (v any ) ([]byte , error ) {
0 commit comments