For example, this error:
javax.xml.bind.UnmarshalException: unexpected element (uri:"", local:"customer"). Expected elements are (none)
when unmarshalling this XML:
to this class, is fixed by adding the annotation @XmlRootElement to the class so it looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<customer id="100">
<age>23</age>
<name>Daffy Duck</name>
</customer>
import javax.xml.bind.annotation.*;
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "customerType", propOrder = {
"id",
"name",
"age"
})
public class Customer {
@XmlElement
String name;
@XmlElement
int age;
@XmlAttribute
int id;
}
Works like a charm, thanks!
ReplyDeleteCode Mule: No @Xmlrootelement Annotation >>>>> Download Now
ReplyDelete>>>>> Download Full
Code Mule: No @Xmlrootelement Annotation >>>>> Download LINK
>>>>> Download Now
Code Mule: No @Xmlrootelement Annotation >>>>> Download Full
>>>>> Download LINK