-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Another JSON encoder support like gin support jsoniter #1698
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
Comments
meanwhile you can create utility functions func asJSON(c echo.Context, code int, i interface{}) error {
response := c.Response()
header := response.Header()
if header.Get(echo.HeaderContentType) == "" {
header.Set(echo.HeaderContentType, echo.MIMEApplicationJSONCharsetUTF8)
}
response.Status = code
return jsoniter.ConfigCompatibleWithStandardLibrary.NewEncoder(response.Writer).Encode(i)
} which is pretty much same what echo does in echo.context.json() and respond in handler data := struct{ ID int64 }{ID: 1}
return asJSON(c, http.StatusOK, data) for request data binding: if err := jsoniter.ConfigCompatibleWithStandardLibrary.NewDecoder(c.Request().Body).Decode(&payload); err != nil {
return err
} just to be annoying. This is interesting go podcast about json with standard library json package maintainer https://changelog.com/gotime/141 they talk about std encoding/json and other packages, some insights what encoding/json is and what it is not. |
This comes up from time to time. See also #1394 and #1177. @jeyldii What is the reason behind your request? Do you see performance issues for your real world usage of echo? We just made the experience that JSON serialization is usually not the bottleneck for real applications (mostly databases and object stores are). But your mileage may vary. |
Hi, |
Understood. I'm not sure adding complexity is worth it, but let's keep the discussion open and see if we want to add that for v5 |
@lammel I'd also like to be able to customise the JSON implementation. In my case it's not jsoniter but google/jsonapi. This is unrelated to bottlenecks for me, and more to the aesthetics of the API. I'd be happy to raise a PR. I'm thinking an implementation similar to how the binder is done (i.e. use an |
I wonder gin has jsoniter support. Let's integrate jsoniter like gin. Jsoniter better than encoding/json
Expected behaviour
go build -tags=jsoniter .
Actual behaviour
No support another json encoder
Steps to reproduce
Let's discuss about this
The text was updated successfully, but these errors were encountered: