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?