users@jersey.java.net

Re: [Jersey] Setting an Xml List name for Jersey

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Mon, 24 Nov 2008 10:54:18 +0100

Hi John,

Currently the only way you can define the XML root element name for a
list of JAXB elements is to create a wrapper using JAXB.

We could support an annotation on the resource method that defines the
root element name, but this of course means that you need to utilize
this annotation every time you return the list. It would be better if
there was an explicit type that could be reused, for example:

  public JAXBList<T> extends ArrayList<T> implements
XmlRootElementIdentifier {
     QName getRootElementName() { ... }
  }

Paul.

On Nov 23, 2008, at 8:21 PM, John O'Conner wrote:

> Maybe this isn't *directly* Jersey related. I suspect this is more
> an issue of my Jaxb lack of knowledge. Still, I'm experiencing this
> while working with Jersey, so maybe someone has the info?
>
> I've configured my ws to return this in my AccountsResource class:
> @GET
> public List<AccountSummaryDTO> getAccounts() {
> ...
>
> This works beautifully EXCEPT that the root element is named
> AccountSummaryDTOes...ugh:
> <AccountSummaryDTOes>
> <accountSummary>
> <company>sldkfjsl</company>
> <distributorName>iejlde</distributorName>
> <id>4</id>
> <infoComplete>true</infoComplete>
> <name>0014a0000002</name>
> <serviceLevel>3</serviceLevel>
> </accountSummary>
> <accountSummary>
> <distributorName>oiroiroiru</distributorName>
> <id>332</id>
> <infoComplete>false</infoComple
> ...
>
> I'd like the root element to be accountSummaryList. But I can't
> quite figure out where that should be configured. Do I need to
> create a wrapper around List<AccountSummaryDTO> and use XmlRoot
> there? Or can I tell Jersey/Jaxb to use a different name for the
> List itself?
>
> Thanks!
>
>