users@jersey.java.net

Re: [Jersey] Simple attempt to output JSON from JAXB class still returning JAXB

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Thu, 05 Nov 2009 09:45:00 +0100

On Nov 4, 2009, at 8:42 PM, Paul Taylor wrote:

> Jakub Podlesak wrote:
>
>
>> instead of creating Marshaller, try to get JSONMarshaller (see [1])
>> and than call marshallToJSON method ([2]).
>>
>> HTH,
>>
>> ~Jakub
>>
>> [1]https://jersey.dev.java.net/nonav/apidocs/1.1.2-ea/jersey/com/sun/jersey/api/json/JSONJAXBContext.html
>> #createJSONMarshaller()
>> [2]https://jersey.dev.java.net/nonav/apidocs/1.1.2-ea/jersey/com/sun/jersey/api/json/JSONMarshaller.html
>> #marshallToJSON%28java.lang.Object,%20java.io.Writer%29
>>
>>
> Thanks that works , didnt notice these because my ide was still
> pointing at json 1.0.3, but dont really know why it just doesnt
> override the existing marshal methods to return json instead of xml.

The Marshal and Unmarshal interfaces are too specific to XML for all
methods on those interfaces to work correctly for JSON. It was cleaner
and clearer to expose explicit interfaces for JSON. In addition the
JSONJAXBContext has to also work correctly when XML is utilized.

Paul.