users@jersey.java.net

RE: [Jersey] Response into UTF-16 encoding

From: Patrick Sauts <patrick.viadeo_at_gmail.com>
Date: Tue, 13 Apr 2010 10:08:31 +0200

Hi Paul,

 

We are using JAXB 2.2.

By logging an issue do you mean send a mail to issues_at_jersey.dev.java.net ?

Thank you for your answers.

 

Patrick.

 

De : Paul.Sandoz_at_Sun.COM [mailto:Paul.Sandoz_at_Sun.COM]
Envoyé : lundi 12 avril 2010 19:20
À : users_at_jersey.dev.java.net
Cc : Guillaume Hiron
Objet : Re: [Jersey] Response into UTF-16 encoding

 

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.

 

 

 

Ce message entrant est certifié sans virus connu.
Analyse effectuée par AVG - www.avg.fr
Version: 9.0.801 / Base de données virale: 271.1.1/2805 - Date: 04/12/10
08:32:00