I have an Object which has a collection element. I am certain that it has values in the collection. When the object values are unmarshalled, I do not get any single values in the XML output. Do you think the way I have named my wrapper object is incorrect?
Here is my code:
@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;
}
}
Based on your mapping the expected XML is the following, chances are your XML does not have the appropriate namespace qualification:
Note that expected namespace on the root element is due to the
namespace
specified on the@XmlRootElement
annotation on theHistory
class: