Skip to content

Commit

Permalink
remove the dependency on github.com/json-iterator/go. (#539)
Browse files Browse the repository at this point in the history
That module uses github.com/modern-go/reflect2 which is broken.

First, it is brittle because it relies on golang's implementation
details that are not stable across golang releases. For example,
reflect2 was broken when go 1.18 came out.

Second, reflect2 is effectively unmaintained:
  modern-go/reflect2#24 (comment)

Json-iterator itself has had correctness issues like
  json-iterator/go#413.

The Kubernetes project has mostly removed the dependency on json-iterator
in patches like
  kubernetes/kubernetes#105030.

Moreover, the Kubernetes authors found it out that json-iterator puts
a lot of load on the allocator, so even the performance gains are
questionable.

Let us remove dependencies on json-iterator and reflect2.
  • Loading branch information
dominiquelefevre committed Jan 3, 2024
1 parent aaf45fd commit 290805f
Show file tree
Hide file tree
Showing 6 changed files with 5 additions and 45 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,7 @@ There are several hooks to customize the behavior of the go-restful package.
- Trace logging
- Compression
- Encoders for other serializers
- Use [jsoniter](https://github.com/json-iterator/go) by building this package using a build tag, e.g. `go build -tags=jsoniter .`
- Use the package variable `TrimRightSlashEnabled` (default true) to control the behavior of matching routes that end with a slash `/`
- Use the package variable `TrimRightSlashEnabled` (default true) to control the behavior of matching routes that end with a slash `/`

## Resources

Expand Down
7 changes: 4 additions & 3 deletions entity_accessors.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package restful
// that can be found in the LICENSE file.

import (
"encoding/json"
"encoding/xml"
"strings"
"sync"
Expand Down Expand Up @@ -127,7 +128,7 @@ type entityJSONAccess struct {

// Read unmarshalls the value from JSON
func (e entityJSONAccess) Read(req *Request, v interface{}) error {
decoder := NewDecoder(req.Request.Body)
decoder := json.NewDecoder(req.Request.Body)
decoder.UseNumber()
return decoder.Decode(v)
}
Expand All @@ -146,7 +147,7 @@ func writeJSON(resp *Response, status int, contentType string, v interface{}) er
}
if resp.prettyPrint {
// pretty output must be created and written explicitly
output, err := MarshalIndent(v, "", " ")
output, err := json.MarshalIndent(v, "", " ")
if err != nil {
return err
}
Expand All @@ -158,5 +159,5 @@ func writeJSON(resp *Response, status int, contentType string, v interface{}) er
// not-so-pretty
resp.Header().Set(HEADER_ContentType, contentType)
resp.WriteHeader(status)
return NewEncoder(resp).Encode(v)
return json.NewEncoder(resp).Encode(v)
}
2 changes: 0 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
module github.com/emicklei/go-restful/v3

go 1.13

require github.com/json-iterator/go v1.1.12
15 changes: 0 additions & 15 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,15 +0,0 @@
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 h1:ZqeYNhU3OHLH3mGKHDcjJRFFRrJa6eAM5H+CtDdOsPc=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
11 changes: 0 additions & 11 deletions json.go

This file was deleted.

12 changes: 0 additions & 12 deletions jsoniter.go

This file was deleted.

0 comments on commit 290805f

Please sign in to comment.