Skip to main content

Unmarshalling error - unexpected root element

3 replies [Last post]
Joined: 2003-11-13

I created and deployed a web service using JAX-WS. The deployment worked fine. My client can create JAXB generated objects and send them to the server implementation class.

From the server implemenation class I wanted to pass the JAXB classes to a EJB but they do not implement Serializable. So I decided to unmarshal the JAXB Ojbect and pass XML to the EJB.

As a test I populated JAXB objects and marshaled then and then unmarshaled the XML and got the following exception:

[org.xml.sax.SAXParseException: unexpected root element (uri:"", local:"pData"). Expected elements are <{}solve>,<{}solveResponse>,<{}SolveException>]

I understand that my toplevel element must be solve and I can see from my XML string that it is not(top lines only included):

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

When I snoop the SOAP call I do find the solve element:


Any ideas on what I'm doing incorrectly?

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2003-06-25

My guess is that the marshalling code marshals the JAXB Object without a root element. So you get an exception when it is unmarshalled. More on this later.

So try the following.

In your test code,
a. either wrap the JAXBObject value into a JAXBElement
instance and marshal the JAXBElement instance.

b. or make sure the JAXB Object passed to the marshal()
method is annotated with an @XmlRootElement.

Either of the above should ensure that the JAXB OBject is marshalled with a root element. So the unmarshal will succeed.

Joined: 2003-11-13

I am not able to modify the XSD, so I added the @XmlRootElement and re-executed my test client. The unmarshaller returns a JAXBElement that contains my Solve object in its getValue() method.

Thanks for the help.

Joined: 2004-03-18

You can make the schema derived classes implement Serializable by using the following customization

See the inline-customize sample for an example on how to specify customizations.