能否請您診斷爲什麼我的代碼打印出[NULL,NULL,NULL,NULL]:JAXB解組返回空值的屬性
Unmarshaller m = JAXBContext.newInstance(Roles.class).createUnmarshaller();
Roles root = m.ummarshal(new FileReader("test.xml"));
System.out.println(root);
我試圖在getter和setter方法不要在eclipse調試,但斷點」牛逼命中
的test.xml
<?xml version="1.0" encoding="UTF-8" ?>
<Roles>
<Ele Id="1" Value="Yes"/>
<Ele Id="2" Value="Yes"/>
<Ele Id="3" Value="No"/>
<Ele Id="4" Value="Yes"/>
</Roles>
Roles.java
@XmlRootElement(name="Roles")
public class Roles {
private List<Ele> EleList;
public Roles() {super();}
@XmlElement(name="Ele")
public List<Ele> getEleList() {return EleList;}
public void setEleList(List<Ele> EleList) {this.EleList = EleList;}
public String toString() {return EleList.toString();}
}
Ele.java
public class Ele {
@XmlAttribute
private String Id;
@XmlAttribute
private String Value;
public Ele(){super();}
public String getId() {return Id;}
public void setId(String id) {Id = id;}
public String getValue() {return Value;}
public void setValue(String value) {Value = value;}
public String toString() { if(Id == null || Value == null) return null; else return Id + Value;}
}
在這種情況下,你可以發佈,作爲一個答案,並接受數天。 –