我有一个具有集合元素的Object。我确信它在集合中具有价值。当对象值被解组时,我在XML输出中没有得到任何单个值。你认为我命名我的包装器对象的方式不正确吗?
这是我的代码:
@XmlRootElement(namespace = "http://www.myself.com/schema/me/v16", name = "history")
@XmlAccessorType(XmlAccessType.NONE)
public class History extends SuperRecord {
private List<PatientHistoryFinding> medicalHistory;
@XmlElement(name = "medicalHistory")
@XmlElementWrapper(name = "medicalHistoryList")
public List<PatientHistoryFinding> getMedicalHistory() {
return medicalHistory;
}
public void setMedicalHistory(List<PatientHistoryFinding> medicalHistory) {
this.medicalHistory = medicalHistory;
}
}
@XmlRootElement(namespace = "http://www.myself.com/schema/me/v16", name = "patientHistoryFinding")
@XmlAccessorType(XmlAccessType.NONE)
public class PatientHistoryFinding extends HistoryFinding {
private String question;
@XmlElement
public String getQuestion() {
return question;
}
public void setQuestion(String question) {
this.question = question;
}
}
@XmlAccessorType(XmlAccessType.NONE)
public abstract class SuperRecord{
protected int id;
@XmlElement
public int getId() {
return id;
}
@Override
public void setId(int id) {
this.id = id;
}
}
答案 0 :(得分:1)
根据您的映射,预期的XML如下所示,您的XML可能没有相应的命名空间限定条件:
<?xml version="1.0" encoding="UTF-8"?>
<ns0:history xmlns:ns0="http://www.myself.com/schema/me/v16">
<id>0</id>
<medicalHistoryList>
<medicalHistory/>
<medicalHistory/>
</medicalHistoryList>
</ns0:history>
请注意,根元素上的预期命名空间是由namespace
类@XmlRootElement
注释上指定的History
引起的:
@XmlRootElement(namespace = "http://www.myself.com/schema/me/v16", name = "history")
@XmlAccessorType(XmlAccessType.NONE)
public class History extends SuperRecord {