How to set the charset with JAX-RS?

deamon picture deamon · Aug 7, 2010 · Viewed 72.6k times · Source

How can I set the charset with JAX-RS? I've tried @Produces("text/html; charset=UTF-8") but that was ignored and only text/html was send with the HTTP header. I want to set the charset within a MessageBodyWriter, but don't want to extract the media type by analysing the @Produces annotation via reflection by myself.

Answer

Adrian Petrescu picture Adrian Petrescu · Sep 27, 2012

As Daemon pointed out in a comment, the latest versions of JAX-RS (including the stable version as of September 2012) now do support the @Produces syntax. So you can just use:

@Produces("text/html; charset=UTF-8")