users@jersey.java.net

Re: [Jersey] jersey 1.0.2: issue with unmarshaling utf-8 json messages

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Tue, 10 Mar 2009 11:57:08 +0100

Hi Sergey,

Thanks for finding this. Jakub can you fix this?

Thanks,
Paul.

On Mar 6, 2009, at 12:48 PM, Privalov, Sergey wrote:

> 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
>