users@jersey.java.net

Re: [Jersey] XML root element customaization

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Mon, 31 Aug 2009 18:08:33 +0200

Hi,

Unfortunately, this is an annoying Jersey bug.

Note that JAXB does not know how to serialize Collection<T> so we have
implemented it in Jersey.

In hind sight we should of implemented this, but we cannot change the
default behavior without breaking existing clients that currently rely
on the wire format. We need some addition property to make this
happen. Can you log an issue?

Thanks,
Paul.

On Aug 31, 2009, at 6:01 PM, Herak Sen wrote:

> I could not find a way to change the root element of XML generated
> when a collection is returned ( without writing custom message
> writers).
> e.g.
>
> /*Bean */
>
> @XmlRootElement(name="customer")
> public class CustomerBean
> {
> public int id = 10;
> public String name = "John";
> }
>
> /*REST Resource */
> public Collection< CustomerBean > test()
> {
> return Collections.singletonList(new CustomerBean ());
> }
>
> /*Generated XML */
>
> <customerBeans> -- I thought the root element will be
> ‘customers’, is it a JAXB stuff?
> <customer>
> <id>10</id>
> <name>John</name>
> </customer>
> </customerBeans>
>
> Herak