首页 文章

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

提问于
浏览
1
<collection>
<Car>
<Car>
<Car>
</collection>

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

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

@Wrapped(element = "cars")没有被拾取 .
1)不知道"jboss having RESTEasy included"是否意味着我甚至不需要担心导入另一个库以便我可以使用@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 回答

  • 3

    您应该能够使用 @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 注释将不起作用 .

相关问题