Well, JSON should be encoded in unicode (either UTF-8, UTF-16 or UTF-32,
with UTF-8 as the default), so the clients shouldn't be having a problem if
their JSON parsers are correct.
However, you may want to try the :escape-non-ascii option that Cheshire and
Ring-JSON have. e.g.
(wrap-json-response app {:escape-non-ascii true})
This will ensure all strings in the JSON are ASCII-encoded, which may be
easier for the clients you're trying to support.
- James
On 24 June 2015 at 15:29, Jonathon McKitrick <[email protected]> wrote:
> Thanks, James.
>
> To clarify, Compojure has no problems serving the JSON content. But the
> SBCL common lisp app and a third-party app (Klipfolio) both are choking on
> the output. I was able to fix the SBCL app by telling Babel to use latin-1
> encoding, but I need another solution for the output to Klipfolio. It's
> probably a knowledge gap on my part of correct use of encodings, and I just
> haven't found the 'correct' solution yet.
>
> On Wednesday, June 24, 2015 at 9:23:36 AM UTC-4, James Reeves wrote:
>>
>> Yes, you can return a full response map with the desired encoding:
>>
>> (GET "/" []
>> {:status 200
>> :headers {"Content-Type" "text/html; charset=ISO-8859-1"}
>> :body "Hello World"})
>>
>> Or use the ring.util.response namespace:
>>
>> (GET "/" []
>> (-> (resp/response "Hello World")
>> (resp/charset "ISO-8859-1")))
>>
>> Or write some middleware to change the charset globally:
>>
>> (defn text-response? [response]
>> (some-> (resp/get-header response "Content-Type")
>> (.startsWith "text/")))
>>
>> (defn wrap-charset [handler charset]
>> (fn [request]
>> (let [response (handler request)]
>> (if (text-response? response)
>> (resp/charset response "ISO-8859-1")
>> response))))
>>
>> However, it's odd that you "can't consume UTF-8 encoding". Are you sure
>> that's the problem?
>>
>> - James
>>
>>
>> On 24 June 2015 at 14:47, Jonathon McKitrick <[email protected]> wrote:
>>
>>> I have a web app that apparently cannot consume UTF-8 encoding. Can
>>> compojure generate responses in latin-1 encoding?
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Clojure" group.
>>> To post to this group, send email to [email protected]
>>> Note that posts from new members are moderated - please be patient with
>>> your first post.
>>> To unsubscribe from this group, send email to
>>> [email protected]
>>> For more options, visit this group at
>>> http://groups.google.com/group/clojure?hl=en
>>> ---
>>> You received this message because you are subscribed to the Google
>>> Groups "Clojure" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to [email protected].
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Groups
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.