diff --git a/binding/json.go b/binding/json.go index 486b973..20aae8c 100644 --- a/binding/json.go +++ b/binding/json.go @@ -5,10 +5,13 @@ package binding import ( - "encoding/json" "net/http" + + "github.com/json-iterator/go" ) +var json = jsoniter.ConfigCompatibleWithStandardLibrary + type jsonBinding struct{} func (jsonBinding) Name() string { diff --git a/context_test.go b/context_test.go index 96e9f08..f57fa6f 100644 --- a/context_test.go +++ b/context_test.go @@ -582,8 +582,8 @@ func TestContextRenderIndentedJSON(t *testing.T) { c.IndentedJSON(201, H{"foo": "bar", "bar": "foo", "nested": H{"foo": "bar"}}) assert.Equal(t, w.Code, 201) - assert.Equal(t, w.Body.String(), "{\n \"bar\": \"foo\",\n \"foo\": \"bar\",\n \"nested\": {\n \"foo\": \"bar\"\n }\n}") - assert.Equal(t, w.HeaderMap.Get("Content-Type"), "application/json; charset=utf-8") + assert.Equal(t, "{\n \"bar\":\"foo\",\n \"foo\":\"bar\",\n \"nested\":{\n \"foo\":\"bar\"\n }\n}", w.Body.String()) + assert.Equal(t, "application/json; charset=utf-8", w.HeaderMap.Get("Content-Type")) } // Tests that no Custom JSON is rendered if code is 204 @@ -595,7 +595,7 @@ func TestContextRenderNoContentIndentedJSON(t *testing.T) { assert.Equal(t, 204, w.Code) assert.Equal(t, "", w.Body.String()) - assert.Equal(t, w.HeaderMap.Get("Content-Type"), "application/json; charset=utf-8") + assert.Equal(t, "application/json; charset=utf-8", w.HeaderMap.Get("Content-Type")) } // Tests that the response is serialized as Secure JSON diff --git a/errors.go b/errors.go index f38d3ff..26d4e47 100644 --- a/errors.go +++ b/errors.go @@ -6,11 +6,14 @@ package gin import ( "bytes" - "encoding/json" "fmt" "reflect" + + "github.com/json-iterator/go" ) +var json = jsoniter.ConfigCompatibleWithStandardLibrary + type ErrorType uint64 const ( diff --git a/errors_test.go b/errors_test.go index 1aa0cdd..a0d9550 100644 --- a/errors_test.go +++ b/errors_test.go @@ -5,7 +5,6 @@ package gin import ( - "encoding/json" "errors" "testing" @@ -32,7 +31,7 @@ func TestError(t *testing.T) { }) jsonBytes, _ := json.Marshal(err) - assert.Equal(t, string(jsonBytes), "{\"error\":\"test error\",\"meta\":\"some data\"}") + assert.Equal(t, "{\"error\":\"test error\",\"meta\":\"some data\"}", string(jsonBytes)) err.SetMeta(H{ "status": "200", @@ -91,7 +90,7 @@ Error #03: third H{"error": "third", "status": "400"}, }) jsonBytes, _ := json.Marshal(errs) - assert.Equal(t, string(jsonBytes), "[{\"error\":\"first\"},{\"error\":\"second\",\"meta\":\"some data\"},{\"error\":\"third\",\"status\":\"400\"}]") + assert.Equal(t, "[{\"error\":\"first\"},{\"error\":\"second\",\"meta\":\"some data\"},{\"error\":\"third\",\"status\":\"400\"}]", string(jsonBytes)) errs = errorMsgs{ {Err: errors.New("first"), Type: ErrorTypePrivate}, } diff --git a/render/json.go b/render/json.go index 8b64f53..17e6ac8 100644 --- a/render/json.go +++ b/render/json.go @@ -6,10 +6,13 @@ package render import ( "bytes" - "encoding/json" "net/http" + + "github.com/json-iterator/go" ) +var json = jsoniter.ConfigCompatibleWithStandardLibrary + type JSON struct { Data interface{} } diff --git a/vendor/vendor.json b/vendor/vendor.json index e520540..547bb2e 100644 --- a/vendor/vendor.json +++ b/vendor/vendor.json @@ -33,6 +33,12 @@ "revision": "5a0f697c9ed9d68fef0116532c6e05cfeae00e55", "revisionTime": "2017-06-01T23:02:30Z" }, + { + "checksumSHA1": "gWQ2ncPI6qpTwS3e6/ShPwUP1uo=", + "path": "github.com/json-iterator/go", + "revision": "b1afefe0580e6e818dd50da9593f477c80ccd67d", + "revisionTime": "2017-07-07T13:43:33Z" + }, { "checksumSHA1": "9if9IBLsxkarJ804NPWAzgskIAk=", "path": "github.com/manucorporat/stats",