users@jersey.java.net

Re: [Jersey] Response into UTF-16 encoding

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Tue, 13 Apr 2010 12:12:25 +0200

On Apr 13, 2010, at 11:55 AM, Patrick Sauts wrote:

> The declaration on the resource is
> @Produces( { MediaType.APPLICATION_JSON,
> MediaType.APPLICATION_XML, "specialxml/xml; charset=UTF-16" })
>
>
> In facts we change mediatype from "specialxml/mxl; charset=UTF-16" to
> "application/xml; charset=UTF-16" in the writeTo method and that
> made it
> work fine.
> If we leave it to "specialxml/mxl; charset=UTF-16" we have <?xml
> version="1.0" encoding="UTF-8"> on top of the xml response.
>
> But maybe we were doing wrong at the first place.
>

I think it may be related to your original implementation of the
provider supporting "specialxml/xml". What was that before you
modified it to work?

Note that for JAXB the following media types are only supported text/
xml, application/xml and application/*+xml so "specialxml/xml"
requires some adaption. Is that why you are overriding JSONWithPadding?

Your @Produces annotation on the resource method does not declare that
JavaScript will be produced, so in effect the JSON padding will never
occur.

Paul.

> Pat.
>
> -----Message d'origine-----
> De : Paul.Sandoz_at_Sun.COM [mailto:Paul.Sandoz_at_Sun.COM]
> Envoyé : mardi 13 avril 2010 11:01
> À : users_at_jersey.dev.java.net
> Cc : Guillaume Hiron
> Objet : Re: [Jersey] Response into UTF-16 encoding
>
>
> On Apr 13, 2010, at 10:28 AM, Patrick Sauts wrote:
>
>> Hi Paul,
>>
>> Thanks to the code you sent us we’ve found a solution,
>>
>> @Produces("specialxlm/xml; charset=UTF-16")
>> @Provider
>> public class SpecialXMLProvider extends JSONWithPaddingProvider {
>> …
>> @Override
>> public void writeTo(…){
>> …
>> super.writeTo(t, type, genericType, annotations,
>> new MediaType("application", "xml", mediaType.getParameters()),
>> httpHeaders, entityStream);
>>
>> …
>> And it works fine that way.
>>
>
> OK.
>
> I am still confused as to why the XML document, in your first email,
> was encoded in UTF-16 and not UTF-8.
>
> Are you declaring an @Produces method on the resource method that
> returns the JSON with padding?
>
> If you have the time to create a simple test case i can investigate
> further, as it seems the work around you have implemented should not
> be required i.e. it should just work as you expected.
>
> Paul.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>
> 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
> 20:32:00
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>