Root element name in collections returned by RESTEasy

后端 未结 1 442
陌清茗
陌清茗 2021-01-11 10:08

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

相关标签:
1条回答
  • 2021-01-11 10:46

    Appeared to be a case of RTFM: RestEasy docs - Arrays and Collections of JAXB Objects

    So, if we wanted to output this XML

    <foo:list xmlns:foo="http://foo.org">
        <customer><name>bill</name></customer>
        <customer><name>monica</name></customer>
    </foo:list>
    

    We would use the @Wrapped annotation as follows:

    @GET
    @Path("list")
    @Produces("application/xml")
    @Wrapped(element="list", namespace="http://foo.org", prefix="foo")
    public List<Customer> getCustomerSet() { ... }
    

    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).

    0 讨论(0)
提交回复
热议问题