Closed lvscar closed 6 years ago
Will fix this.
Which method do you use to write JSON response?
My plan is to set the default charset
to utf-8
only when the response is going to be JSON.
getJson
, posJson
, etc.GetJson
, PostJson
, etcIt looks like you use Response.json
, the other two methods already use utf-8
by default.
Try Jaguar 2.1.26
, it uses utf-8
by default for Response.json
.
Would this be enough?
I prefer directly construct JSON and Response object because heavily depend on toEncodable in my case.
Beside JSON response, any XHR request/response should be encoded in utf-8. ref. And because utf-8 is backwards compatibility with ASCII 0, I hope Jaguar could use the utf-8 as default charset for all kinds of response.
Try Jaguar
2.1.26
, it uses utf-8
by default for Response
.
Let me know if it has fixed the problem.
After upgrade to Jaguar 2.1.27. I confirm the issue is resolved!
@lvscar Here is a video about various methods for JSON serialization using Jaguar: https://www.youtube.com/watch?v=zW_PTzmw2N0&t=12s
There is also jaguar_serializer
package that generates serializersfor models: https://github.com/Jaguar-dart/jaguar_serializer/wiki
New tricks learned! "ctx.bodyAsJson(convert: Func)" & "Map toJSON" both very handy in common api getaway programming. Love Jaguar more~
After upgrade to Jaguar 2.2.10 , I found the default utf-8 charset for Response & Response.json was missing.
PR #123 submitted
In the Responseobject initializing process, If the response value contain some non-latin characters, at the same time the user didn't set the optional charset parameter to 'utf-8'. The Jaguar server will just output an "empty" HTTP response ( content-length: 0 , empty HTTP body) without any error message displayed in terminal .
I found there have some related discussion and some information about standards. According to these linked standard webpages, we could set the default charset to utf-8 at least for JSON response safely.