我JAXB
用于将配置映射XML
到 Java 对象。可以从 编辑此配置UI
,这就是为什么要将其传输到 UI,反之亦然。我绝对需要解组json
为 Java 对象。因此,它需要有 setter 方法List
。
如何使用 JAXB 为 POJO 类的 List 属性生成 setter 方法?
出于安全原因,不会为 List 对象生成 setter。
/**
* Gets the value of the dateIntervals property.
*
* <p>
* This accessor method returns a reference to the live list,
* not a snapshot. Therefore any modification you make to the
* returned list will be present inside the JAXB object.
* This is why there is not a <CODE>set</CODE> method for the dateIntervals property.
*
* <p>
* For example, to add a new item, do as follows:
* <pre>
* getDateIntervals().add(newItem);
* </pre>
*
*
* <p>
* Objects of the following type(s) are allowed in the list
* {@link DateInterval }
*
*
*/
为此,您需要创建 List 变量。此 List 变量的 setter getter 方法如下。
package foo.bar.me.too;
import java.util.List;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement(name="VisitorDataList")
public class visitordatalist {
List<visitordata> vstd;
@XmlElement(name="VisitorData")
public List<visitordata> getVstd() {
return vstd;
}
public void setVstd(List<visitordata> vstd) {
this.vstd = vstd;
}
}