users@jersey.java.net

[Jersey] Re: JSON with JAXBContextResolver and JAXB

From: Tatu Saloranta <tsaloranta_at_gmail.com>
Date: Wed, 8 Aug 2012 08:10:57 -0700

On Wed, Aug 8, 2012 at 8:01 AM, Tatu Saloranta <tsaloranta_at_gmail.com> wrote:
> On Tue, Aug 7, 2012 at 11:33 PM, James Green <james.mk.green_at_gmail.com> wrote:
>>
>>
>> On 7 August 2012 23:38, Tatu Saloranta <tsaloranta_at_gmail.com> wrote:
>>>
>>> On Tue, Aug 7, 2012 at 2:54 PM, James Green <james.mk.green_at_gmail.com>
>>> wrote:
>>> > OK, I've hooked up a real simple project with a Customer bean having
>>> > @XmlRootElement. It works out the of box with an Application activator
>>> > returning a JacksonJaxbJsonProvider.
>>> >
>>> > I've switched on SerializationFeature.WRAP_ROOT_VALUE to mirror our XML
>>> > api
>>> > documentation a little closer. Two things are otherwise immediately
>>> > apparent:
>>> >
>>> > 1. The JSON has an empty root name:
>>> >
>>> > {
>>> > "": {
>>> > "id": 2
>>> > }
>>> > }
>>> >
>>> > Unless I expressly set the name of the @XmlRootElement. Can't find
>>> > reference
>>> > to this on Google though. Any ideas?
>>>
>>> This does seem odd: the default behavior, if annotation is not used
>>> (that, or Jackson's @JsonRootName), would be to use simple class name
>>> of the value class.
>>
>>
>> Mind taking a look?
>>
>> Customer model in full: http://pastebin.com/RjdTvagY
>> JAX-RS Activator: http://pastebin.com/9v2CkbLz
>
> I'll have a look, see if anything jumps out.

Ah. This is due to interaction between JAXB annotation introspector
(Jackson component), and Jackson's root-wrapper. Empty String is not
converted properly it seems, and all tests use either explicit name,
or omit @XmlRootElement.
That is, this looks like a bug in Jackson.

I will add a Jira issue and get this fixed. As a work-around, you can
either leave out the annotation (unless you have to use JAXB for XML);
or add the name argument.

-+ Tatu +-