users@jersey.java.net

jersey 1.0.2: issue with unmarshaling utf-8 json messages

From: Privalov, Sergey <s.privalov_at_itransition.com>
Date: Fri, 6 Mar 2009 13:48:09 +0200

Hello,

 

It's looks like that the list of entities which contains unicode
characters are unmarshaled in incorrect way from the json. Seems that
problem is in the following piece of code:

 

package com.sun.jersey.json.impl.provider.entity;

 

...

 

public class JSONListElementProvider extends AbstractListElementProvider
{

     

     ...

 

    @Override

    protected final XMLStreamReader getXMLStreamReader(Class<?>
elementType, MediaType mediaType, Unmarshaller u, InputStream
entityStream) throws XMLStreamException {

        JSONConfiguration c = JSONConfiguration.DEFAULT;

        if (u instanceof JSONConfigurated) {

            c = ((JSONConfigurated) u).getJSONConfiguration();

        }

        return Stax2JsonFactory.createReader(new
InputStreamReader(entityStream), c,
JSONHelper.getRootElementName((Class)elementType), true);

    }

}

 

In our case this problem was fixed by modification this code in the
following way:

 

 

package com.sun.jersey.json.impl.provider.entity;

 

...

 

public class JSONListElementProvider extends AbstractListElementProvider
{

     

     ...

 

    @Override

    protected final XMLStreamReader getXMLStreamReader(Class<?>
elementType, MediaType mediaType, Unmarshaller u, InputStream
entityStream) throws XMLStreamException {

        JSONConfiguration c = JSONConfiguration.DEFAULT;

        final Charset charset = getCharset(mediaType);

        if (u instanceof JSONConfigurated) {

            c = ((JSONConfigurated) u).getJSONConfiguration();

        }

        return Stax2JsonFactory.createReader(new
InputStreamReader(entityStream, charset), c,
JSONHelper.getRootElementName((Class)elementType), true);

    }

}

 

We recompiled corresponded class with our fix and put it into the
classpath before the original jars.

 

Best Regards,

Sergey Privalov