I have an XML to unmarshall with JAXB. The code works fine if I remove all namespace attributes from the elements but I get a null object after unmarshalling if I keep the names
XMLAtribute has atribute namesape, so
@XmlAttribute(name = "Id", namespace="http://schemas.microsoft.com/2003/10/Serialization").
While judging by your xml, the cat is in the same namespace as the animal so
The following code works with JDK 7 (fixed the ns for animal and attribute name for zid).
@XmlRootElement(name = "Animal",namespace = "http://allmycats.com/serviceplatform/1.0/")
public class Animal2{
List<Cat2> cats;
@XmlElement(name = "Cat")
public List<Cat2> getCats() {
return cats;
}
public void setCats(List<Cat2>cats) {
this.cats= cats;
}
}
@XmlRootElement(name = "Cat")
public class Cat2 {
private String zId;
@XmlAttribute(name = "Id", namespace="http://schemas.microsoft.com/2003/10/Serialization/")
public String getzId() {
return zId;
}
public void setzId(String zId) {
this.zId = zId;
}
private String name;
@XmlElement(name = "name")
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}