-
Notifications
You must be signed in to change notification settings - Fork 8.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
context.JSON adds a new line to end of JSON response #2209
Comments
Before 1.5, context.JSON was using json.Marshal Refer Here. In 1.5 this was changed to use encoder.Encode(). Refer Change Encoder adds a line at the end. Refer to this code An issue about this is raised in the golang repository also. |
Linking the PR which caused this issue in the name of performance improvement trading correctness and that too without performance numbers. |
I am also facing an issue because of this redundant newline character addition. I have a java service that sits in front a go service that is using gin framework.
Hence, the consumers of my java service are getting a content length mismatch issue between content-length header and actual content body. |
…onic#2209 (cherry picked from commit 6fa61ce)
gin-gonic#2209 (gin-gonic#2228) * ignore IntelliJ idea generated files * update JSON renderer to use Marshall() instead of Encode(). Fix gin-gonic#2209 * Revert "ignore IntelliJ idea generated files" This reverts commit e7bd017. Co-authored-by: Bo-Yi Wu <appleboy.tw@gmail.com> Co-authored-by: thinkerou <thinkerou@gmail.com>
for those who do not appreciate this change and expect JSONs ending with newline, a straightforward middleware that appends a newline after every response:
|
Description
context.JSON() adds a new line character \n to end of JSON response
How to reproduce
Clone this repo and run
Expectations
Newline character ("\n") must not get added to the end of
{"message":"hello world"}
Actual result
new line character gets added
Environment
The text was updated successfully, but these errors were encountered: