users@jersey.java.net

[Jersey] Re: Set specific encoding in Jersey server

From: Tatu Saloranta <tsaloranta_at_gmail.com>
Date: Thu, 9 Jun 2011 11:21:59 -0700

On Thu, Jun 9, 2011 at 10:22 AM, Maxrunner <joao.rossa_at_gmail.com> wrote:
> So how do i solve this???i used jackson because i wanted some of its pojo
> type properties, but now i cant use iso-8859-1???i thought the @produces
> annotation was used by jersey and not jackson directly. what i find strange
> is that if i open this in the ie or firefox it ask to save to a file and in
> this case i save it as a noteapp file, and when i open it, the charset is
> correct....why?

You can not use ISO-8859-1 because it is illegal for JSON, as per JSON
specification. Only Unicode encodings can be used for JSON.
So do not use non-Unicode encodings; and if consuming content produced
by someone else, tell me it is invalid content, not JSON.

... but if you really REALLY must process it, trick is to take
InputStream, read it using InputStreamReader (with encoding of
ISO-8859-1), and use that Reader, pass to ObjectMapper.
(or read content as a String using that encoding, both work).

I hope this helps,

-+ Tatu +-