Issue with unmarashalling a collection in JAXB using Jersey MOXy implementation

71 views Asked by At

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;
    }
}
1

There are 1 answers

0
bdoughan On

Based on your mapping the expected XML is the following, chances are your XML does not have the appropriate namespace qualification:

<?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>

Note that expected namespace on the root element is due to the namespace specified on the @XmlRootElement annotation on the History class:

@XmlRootElement(namespace = "http://www.myself.com/schema/me/v16", name = "history")
@XmlAccessorType(XmlAccessType.NONE)
public class History extends SuperRecord {