Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

javax.xml.bind.UnmarshalException: unexpected element (uri:"", local:"Group")

Tags:

java

xml

jaxb

unexpected element (uri:"", local:"Group"). Expected elements are <{}group> 

Meet an exception when unmarshalling from xml

JAXBContext jc = JAXBContext.newInstance(Group.class);  Unmarshaller unmarshaller = jc.createUnmarshaller(); Group group = (User)unmarshaller.unmarshal(new File("group.xml")); 

Group class has no any annotation and group.xml just contains data.

Anything can be the cause?

like image 339
user496949 Avatar asked Mar 05 '11 10:03

user496949


1 Answers

It looks like your XML document has the root element "Group" instead of "group". You can:

  1. Change the root element on your XML to be "group"
  2. Add the annotation @XmlRootElement(name="Group") to the Group classs.
like image 115
bdoughan Avatar answered Sep 28 '22 10:09

bdoughan