开发者

resteasy, jaxb - How to produce a collection/list of strings?

开发者 https://www.devze.com 2023-04-07 07:59 出处:网络
Simple task, I need to produce this XML: <collection> <name>bill</name> <name>monica</name>

Simple task, I need to produce this XML:

<collection>
    <name>bill</name>
    <name>monica</name>
<collection>

instead of this (see following example: 19.6. Arrays and Collections of JAXB Objects):

<collection>
  开发者_JAVA技巧  <customer><name>bill</name></customer>
    <customer><name>monica</name></customer>
<collection>

Simple collection with strings. So the question is how to remove surrounding customer element? How can I do this with RESTeasy and JAXB?


On the Customer class map the name property with the @XmlValue annotation:

public class Customer {

    private String name;

    @XmlValue
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

}

For More Information

  • http://blog.bdoughan.com/2011/06/jaxb-and-complex-types-with-simple.html
0

精彩评论

暂无评论...
验证码 换一张
取 消