johnny-b-goode
johnny-b-goode

Reputation: 3893

Unmarshalling works incorrectly: javax.xml.bind.UnmarshalException: unexpected element

Got an exception

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

trying to unmarshall xml, shown below:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?> 
  <ConnectorCommandType> ........ </ConnectorCommandType>

The exception basically says that element is not found in jaxb context. But debugging shows that this class is present and known in current jaxb context. The class ConnectorCommandType was generated from xsd xml as <xs:complexType> element.

Could there be an error in the xsd?

Has anyone faced with problem like that? Any suggestions? Thanks.

Upvotes: 2

Views: 3343

Answers (1)

bdoughan
bdoughan

Reputation: 149007

The solution depends on the answer to the following question:

Is there an @XmlRootElement(name="ConnectorCommandType") annotation on the ConnectorCommandType class, or an @XmlElementDecl(name="ConnectorCommandType") on a create method in the ObjectFactory class?

If the answer is YES

Is there a package-info in your generated model? It appears as though your JAXB (JSR-222) implementation is expecting a namespace qualified document. Something like:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ConnectorCommandType xmlns="YOUR_NAMESPACE_HERE">
     ........ 
</ConnectorCommandType>

For More Information

If the answer is NO

If the ConnectorCommandType element is not associated with a class, then you will need to use one of the unmarshal methods that takes a class parameter.

Upvotes: 1

Related Questions