Skip to content

Commit 0f66814

Browse files
authored
Drop json-iterator dependency (#35544)
1 parent fbe80e6 commit 0f66814

File tree

6 files changed

+75
-73
lines changed

6 files changed

+75
-73
lines changed

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ require (
6161
github.com/go-redsync/redsync/v4 v4.13.0
6262
github.com/go-sql-driver/mysql v1.9.3
6363
github.com/go-webauthn/webauthn v0.13.4
64+
github.com/goccy/go-json v0.10.5
6465
github.com/gogs/chardet v0.0.0-20211120154057-b7413eaefb8f
6566
github.com/gogs/go-gogs-client v0.0.0-20210131175652-1d7215cd8d85
6667
github.com/golang-jwt/jwt/v5 v5.3.0
@@ -75,7 +76,6 @@ require (
7576
github.com/huandu/xstrings v1.5.0
7677
github.com/jaytaylor/html2text v0.0.0-20230321000545-74c2419ad056
7778
github.com/jhillyerd/enmime v1.3.0
78-
github.com/json-iterator/go v1.1.12
7979
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51
8080
github.com/klauspost/compress v1.18.0
8181
github.com/klauspost/cpuid/v2 v2.3.0
@@ -200,7 +200,6 @@ require (
200200
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect
201201
github.com/go-ini/ini v1.67.0 // indirect
202202
github.com/go-webauthn/x v0.1.24 // indirect
203-
github.com/goccy/go-json v0.10.5 // indirect
204203
github.com/golang-jwt/jwt/v4 v4.5.2 // indirect
205204
github.com/golang-sql/civil v0.0.0-20220223132316-b832511892a9 // indirect
206205
github.com/golang-sql/sqlexp v0.1.0 // indirect
@@ -220,6 +219,7 @@ require (
220219
github.com/hashicorp/go-retryablehttp v0.7.8 // indirect
221220
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
222221
github.com/josharian/intern v1.0.0 // indirect
222+
github.com/json-iterator/go v1.1.12 // indirect
223223
github.com/kevinburke/ssh_config v1.4.0 // indirect
224224
github.com/klauspost/pgzip v1.2.6 // indirect
225225
github.com/libdns/libdns v1.1.1 // indirect

modules/json/json.go

Lines changed: 1 addition & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ import (
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
10035
func Marshal(v any) ([]byte, error) {

modules/json/jsongoccy.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Copyright 2025 The Gitea Authors. All rights reserved.
2+
// SPDX-License-Identifier: MIT
3+
4+
package json
5+
6+
import (
7+
"bytes"
8+
"io"
9+
10+
"github.com/goccy/go-json"
11+
)
12+
13+
var _ Interface = jsonGoccy{}
14+
15+
type jsonGoccy struct{}
16+
17+
func (jsonGoccy) Marshal(v any) ([]byte, error) {
18+
return json.Marshal(v)
19+
}
20+
21+
func (jsonGoccy) Unmarshal(data []byte, v any) error {
22+
return json.Unmarshal(data, v)
23+
}
24+
25+
func (jsonGoccy) NewEncoder(writer io.Writer) Encoder {
26+
return json.NewEncoder(writer)
27+
}
28+
29+
func (jsonGoccy) NewDecoder(reader io.Reader) Decoder {
30+
return json.NewDecoder(reader)
31+
}
32+
33+
func (jsonGoccy) Indent(dst *bytes.Buffer, src []byte, prefix, indent string) error {
34+
return json.Indent(dst, src, prefix, indent)
35+
}

modules/json/jsonlegacy.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,10 @@ package json
77

88
import (
99
"io"
10-
11-
jsoniter "github.com/json-iterator/go"
1210
)
1311

1412
func getDefaultJSONHandler() Interface {
15-
return JSONiter{jsoniter.ConfigCompatibleWithStandardLibrary}
13+
return jsonGoccy{}
1614
}
1715

1816
func MarshalKeepOptionalEmpty(v any) ([]byte, error) {

modules/json/jsonv1.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Copyright 2025 The Gitea Authors. All rights reserved.
2+
// SPDX-License-Identifier: MIT
3+
4+
package json
5+
6+
import (
7+
"bytes"
8+
"encoding/json" //nolint:depguard // this package wraps it
9+
"io"
10+
)
11+
12+
type jsonV1 struct{}
13+
14+
var _ Interface = jsonV1{}
15+
16+
func (jsonV1) Marshal(v any) ([]byte, error) {
17+
return json.Marshal(v)
18+
}
19+
20+
func (jsonV1) Unmarshal(data []byte, v any) error {
21+
return json.Unmarshal(data, v)
22+
}
23+
24+
func (jsonV1) NewEncoder(writer io.Writer) Encoder {
25+
return json.NewEncoder(writer)
26+
}
27+
28+
func (jsonV1) NewDecoder(reader io.Reader) Decoder {
29+
return json.NewDecoder(reader)
30+
}
31+
32+
func (jsonV1) Indent(dst *bytes.Buffer, src []byte, prefix, indent string) error {
33+
return json.Indent(dst, src, prefix, indent)
34+
}

modules/lfs/http_client_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ func TestHTTPClientDownload(t *testing.T) {
193193
},
194194
{
195195
endpoint: "https://invalid-json-response.io",
196-
expectedError: "/(invalid json|jsontext: invalid character)/",
196+
expectedError: "/(invalid json|invalid character)/",
197197
},
198198
{
199199
endpoint: "https://valid-batch-request-download.io",
@@ -301,7 +301,7 @@ func TestHTTPClientUpload(t *testing.T) {
301301
},
302302
{
303303
endpoint: "https://invalid-json-response.io",
304-
expectedError: "/(invalid json|jsontext: invalid character)/",
304+
expectedError: "/(invalid json|invalid character)/",
305305
},
306306
{
307307
endpoint: "https://valid-batch-request-upload.io",

0 commit comments

Comments
 (0)