Draft
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Feature: JSON-Iterator Integration Example & Test Fixes
Description
This PR addresses issue #2810 by providing a complete, working example of how to integrate
json-iterator/gowith Gin. Additionally, it includes critical fixes for existing tests that were failing or behaving inconsistently when the-tags=jsoniterbuild tag was active.Changes
1. New Example
examples/json-iteratorjson_iterator_test.goto the existing example. This allows developers to verify the integration in isolation without running the entire suite.encoding/jsonbinding withjson-iteratorfor performance improvements.2. Critical Test Fixes
Running
go test -tags=jsoniter ./...previously caused failures. The following fixes ensure full compatibility:gin_integration_test.go:TestRunEmptyrelied on the default port:8080. When running tests in parallel or on CI/CD (like GitHub Actions), this often resulted inbind: address already in useerrors.:0), eliminating port conflicts.binding/binding_test.go:TestUriBindingfailed becausejson-iteratorbehaves slightly differently thanencoding/jsonon error. Specifically,json-iteratormay allocate an empty map before returning an error, whereas the standard library leaves it asnil.nilor an empty map when an error occurs, preserving correctness for both engines.context_test.go:TestContextBindRequestTooLargeexpected a413 Request Entity Too Largestatus code. However, the underlyingjson-iteratorlibrary returns a400 Bad Requestwhen the body size limit is exceeded.400 Bad Requestwhen thejsoniterbuild tag is active, matching the library's actual behavior.How to Verify
Run the Example
go run -tags=jsoniter examples/json-iterator/main.go # Expected Output: Server starts on :8080Run All Tests (with json-iterator)
Run Standard Tests (Regression Check)
Checklist
masterbranch.-tags=jsoniter.Fixes #2810