users@jersey.java.net

Re: AW: [Jersey] Impossibility to set charset - Is it a bug?

From: Paul Sandoz <Paul.Sandoz_at_oracle.com>
Date: Mon, 9 Aug 2010 10:18:42 +0200

On Aug 9, 2010, at 9:23 AM, Christian Helmbold wrote:

>> What version of Jersey are you using?
>
>
> I'm using Jersey 1.3.
>
>> Where are you declaring the @Produces?
>
> I've declared @Produces("text/html; charset=UTF-8") on the
> MessageBodyWriter and
> @Produces("text/html") on the resource method. I thought that the
> resource
> method should not know about the encoding of the templates. But it
> works, if I
> specify the encoding on the resource method! I am, however, not sure
> whether it
> is better as my workaround with explicitly setting the content type
> or not.
>

Do you intend to have separate MBWs for different charsets or be more
dynamic about the charset to utilize?


>> It should work if declaring on the resource method/class.
>
> Yes, it does. What is the reason, that it doesn't work with the
> MessageBodyWriter?
>

An oversight, but it also introduces some interesting problems to
solve. The @Produces on the MBW may not be concrete. Which @Produces
takes priority? Does one merge the parameters, if so which ones takes
priority if two of the same name are declared, and how does one
compare the parameter names, are they are case insensitive or not
(IIRC that is specific to the definition of the parameter)

I suspect if you intend to say support the charset as a prefix of the
template (or if it is defined in the template, can freemarker do
that?) that you probably want to set this dynamically rather than
statically using annotations.

Paul.