dev@jersey.java.net

Re: [Jersey] element name wrapper for List<Element> returned by Jersey method.

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Mon, 08 Feb 2010 14:43:49 +0100

On Feb 8, 2010, at 2:13 PM, James Russo wrote:

> Hello Paul,
>
>> Yes, it uses the class name of the item class. Our bad it should
>> have used the @XmlRootElement annotation, it present and retained
>> the case.
>
> So, in my case it knew to turn "Person" into the plural
> "people" (rather then persons)?
>

Yes, the pluralizing algorithm will try and do the right thing in
terms of english words (see below).


>> Here are a number of possible solutions:
>>
>> 1) Use the @XmlRootElement defined on the item JAXB class, or same
>> rules to derive the name, and pluralize it (without lower casing it).
>>
>> 2) Annotate the resource method with @XmlRootElement (however that
>> might interfere if the resource class is also a JAXB
>> class)
>>
>> 3) Annotate the JAXB class with a special Jersey annotation (the
>> same can apply for 2 as well).
>>
>>
>> I am leaning towards option 1), unfortunately we cannot make that
>> the default because we will break on the wire backwards
>> compatibility. Do you have any preference or further ideas on the
>> matter?
>>
>
> In my situation I have "Person" and a "People" element which
> contains 1 or more Person elements [1].

Sorry i was not clear.

I mean use the @XmlRootElement name, if present otherwise use the
class name, as the input to the "pluralizer".

Currently there are 2 issues:

1) The input to the "pluralizer" is the class name even if an
@XmlRootElement is present; and

2) It lower cases the pluralized name instead of retaining the same
case.


> The XmlRootElement of my Person element is Person, perhaps I don't
> have my schema setup correctly though. But in this case using
> XmlRootElement would not have helped me. Using uppercase "People"
> would have made it work out of the box for me, but likely not
> everyone. I think that not lower casing it (using whatever case is
> there) would be a good compromise.
>
>> In the interim there is a possible work around without having to
>> change your application code. Implement a resource filter that
>> modifies the entity and wraps it around an instance of Person.
>
> Thanks. I'll check this out.
>

OK.

Paul.