users@jersey.java.net

Re: [Jersey] Response into UTF-16 encoding

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Mon, 12 Apr 2010 19:19:49 +0200

Hi Patrick,

What version of Jersey and JAXB are you using?

On first thought that looks like a bug in JAXB. Jersey does the
following:

     public final void writeTo(
             Object t,
             Class<?> type,
             Type genericType,
             Annotation annotations[],
             MediaType mediaType,
             MultivaluedMap<String, Object> httpHeaders,
             OutputStream entityStream) throws IOException {
         try {
             final Marshaller m = getMarshaller(type, mediaType);
             final Charset c = getCharset(mediaType);
             if (c != UTF8) {
                 m.setProperty(Marshaller.JAXB_ENCODING, c.name());
             }
             writeTo(t, mediaType, c, m, entityStream);
         } catch (JAXBException ex) {
             throw new WebApplicationException(ex, 500);
         }
     }

notice that it sets the character set as a property.

Can you log an issue so we do not forget about this?

Paul.

On Apr 12, 2010, at 6:32 PM, Patrick Sauts wrote:

> Hi,
>
> The problem we are facing is that we need to produce a special xml
> format with a char encoding in UTF-16,
> To do that we’ve written a @Provider for our specific format
> @Produces("specialxlm/xml; charset=UTF-16")
> @Provider
> public class SpecialXMLProvider …
>
> The xml produced is UTF-16 encoded and has the good format but the
> xml header is still :
> <?xml version="1.0" encoding="UTF-8">
>
> The “javax.ws.rs.core.Response” is made using :
> Response.ok().entity(new JSONWithPadding(new
> GenericEntity<ResponseSpecialXml>(responseSpecialXml) {})).build();
>
> My question is, how with this kind of implementation, do I obtain a
> xml response header like :
> <?xml version="1.0" encoding="UTF-16">
>
> Thank you for your time.
>
> Patrick Sauts.
>
>