将Resteasy生成的<collection>元素的名称更改为其他内容?</collection>

时间:2013-06-02 20:44:47

标签: collections jaxb jax-rs resteasy

<collection>
<Car>
<Car>
<Car>
</collection>

我想将标签的名称更改为 我不知道我在用什么 - 它只是Jboss 7.1.1和标准的多模块EAR maven设置。我应该包含RESTEasy,以及他们使用的任何JAXB提供程序。

我有权访问的@XmlElementWrapper注释,但是当我注释JAXRS服务方法“getCars”时它不起作用。它对xml输出没有影响。

@Wrapped(element =“cars”)不起作用b / c我似乎无法导入RESTEasy jax-rs jar。我把它添加到我的pom.xml中但它没有被拾取。
1)不知道“包含RESTEasy的jboss”是否意味着我甚至不需要担心导入另一个库以便我可以使用@Wrapped注释。 2)为了我的目的,我可以使用@XmlElementWrapper注释吗?

@GET
@Produces({MediaType.APPLICATION_XML})
@Path("/")
@XmlElementWrapper(name="cars")//I have access to this annotation but nothing happens
@Wrapped(element="cars")//eclipse doesn't know what this annotation means
public List<car> getCars();

1 个答案:

答案 0 :(得分:4)

您应该可以使用@Wrapped注释完成此操作。

要将此注释添加到项目中,请尝试将此工件添加到pom.xml

    <dependency>
        <groupId>org.jboss.resteasy</groupId>
        <artifactId>resteasy-jaxb-provider</artifactId>
        <version>${resteasy.version}</version>
    </dependency>

另一种选择是创建自己的包装类:

@XmlRootElement(name="cars")
public class CarCollection {
    @XmlElement(name="car")
    private List<Car> articles = new ArrayList<Car>();
}

@GET
@Produces({MediaType.APPLICATION_XML})
@Path("/")
public CarCollection getCars();

仅使用@XmlElementWrapper注释不起作用。