Can JAXB output an ArrayList as comma separated values?

前端 未结 3 1073
臣服心动
臣服心动 2021-01-19 07:56

I have something like

@XmlElementWrapper(name=\"Mylist\")
List myItems = new ArrayList()

and that comes out lik

3条回答
  •  感情败类
    2021-01-19 08:19

    you can accomplish that by making the field transient @XmlTransient and creating a method for calculating a String with a comma-separated.

    @XmlTransient
    List myItems = new ArrayList()
    
    @XmlElement(name = "myItems")
    public String getItemsAsCommasSeparated() {
        return String.join(", ", myItems);
    }
    

    About the wrapping if it is really necessary you will have to wrap the list into a another object.

提交回复
热议问题