• Post Reply Bookmark Topic Watch Topic
  • New Topic

jaxb not unmarshalling xml any element to JAXBElement

 
Ashwin Kumar
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have weservice call, In response when I try to get the xml any element in to JAXBElement.

In schema I have ..

This line throws error.

it throws org.apache.xerces.dom.ElementNSImpl incompatible with javax.xml.bind.JAXBElement error in soap ui.

Why doesn't it covert to JAXBElement?, how do I make it work?
 
Ivan Krizsan
Ranch Hand
Posts: 2198
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!
If the element in question has a minOccurs equal to zero or is nillable, then it must be wrapped in a JAXBElement, since it may be null.
If, however, this is not the case, then JAXB will deliver the unwrapped object representing the element - a org.apache.xerces.dom.ElementNSImpl.
An instance of the ElementNSImpl class represents an arbitrary XML element with namespace support.

It is possible to customize JAXB binding not to use JAXBElement wrappers. See: http://download.oracle.com/docs/cd/E17802_01/webservices/webservices/reference/tutorials/wsit/doc/DataBinding5.html
I do not know if you can configure it to always use JAXBElements.
Best wishes!
 
Ashwin Kumar
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Ivan, In my case it minOccurs is zero so it is wrapped as JAXBElement but the SOAP request/response complains of in compatible with org.apache.xerces.dom.ElementNSImpl.

I also read from the specification that if the lax=true ...

From specification..
"If true, when an element matches a property marked with XmlAnyElement is known to JAXBContext (for example, there's a class with XmlRootElement that has the same tag name, or there's XmlElementDecl that has the same tag name), the unmarshaller will eagerly unmarshal this element to the JAXB object, instead of unmarshalling it to DOM. Additionally, if the element is unknown but it has a known xsi:type, the unmarshaller eagerly unmarshals the element to a JAXBElement, with the unknown element name and the JAXBElement value is set to an instance of the JAXB mapping of the known xsi:type.
As a result, after the unmarshalling, the property can become heterogeneous; it can have both DOM nodes and some JAXB objects at the same time. "

So, I am not sure how to oevercome this issue.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!