Thursday, January 14, 2016

No @XmlRootElement annotation

If you get "Expected elements are (none)" in a javax.xml.bind.UnmarshalException, you probably don't have an @XmlRootElement annotation in the Java object that your code is unmarshalling to.

For example, this error:
javax.xml.bind.UnmarshalException: unexpected element (uri:"", local:"customer"). Expected elements are (none)
when unmarshalling this XML:
<?xml version="1.0" encoding="UTF-8"?>
<customer id="100">
    <age>23</age>
    <name>Daffy Duck</name>
</customer>
to this class, is fixed by adding the annotation @XmlRootElement to the class so it looks like this:
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;

}

2 comments:

  1. Code Mule: No @Xmlrootelement Annotation >>>>> Download Now

    >>>>> Download Full

    Code Mule: No @Xmlrootelement Annotation >>>>> Download LINK

    >>>>> Download Now

    Code Mule: No @Xmlrootelement Annotation >>>>> Download Full

    >>>>> Download LINK

    ReplyDelete

YouTube 5.1 Channel Audio Fail in Browsers

Ignore any blog posts or YouTube videos that claim to show you how to play 5.1 surround from YouTube videos in a browser. They don’t work. A...