I'm using JAX-RS via RestEasy in JBoss AS 6. When my JAX-RS resource returns a collection of items (e.g. via a List), RESTEasy always uses the name collection
as the root element.
E.g.
<collection>
<item>
<description>computer</description>
<price>2500</price>
</item>
<item>
<description>tv</description>
<price>1500</price>
</item>
</collection>
This XML is generated by e.g.:
@Produces("application/xml")
@Path("xml")
@RequestScoped
public class MyResource {
@GET
@Path("myitems")
public List<Item> getMyItems() {
return ...
}
}
As can be seen the root tag that has been created by RESTEasy is always <collection>
.
Jersey on the other hand always creates a name that is the plural form of the element contained in the list:
<items>
<item>
<description>computer</description>
<price>2500</price>
</item>
<item>
<description>tv</description>
<price>1500</price>
</item>
</items>
I know it's possible to create a wrapper type and return that instead of a List, but that's a rather elaborate workaround and makes the code more complicated.
Is it possible to easily specify what the name of the root tag is for collections?
Appeared to be a case of RTFM: RestEasy docs - Arrays and Collections of JAXB Objects
It's thus possible via the @Wrapped annotation. It's a RESTEasy specific one, but this will do for now.
Leaving the question open in case someone has an even better solution (still looking for a global interceptor orso that lets RESTEasy do what Jersey does).