Friday, July 20, 2012

Java webservice considering the space/newline characters as an element


Java webservice considering the space/newline characters as an element

We have developed a java webservice to convert the xml to fixed length payload; unfortunately it was failing with Class cast Exception.

<faultstring>java.lang.String cannot be cast to javax.xml.bind.JAXBElement</faultstring>

 
After debugging we have identified the parser considering the new line character in the XML payload as the JAXBElement.

 
We tried removing the new line characters and the spaces in the xml payload and it worked fine.



After a long struggle we have identified the root cause.

Root cause:

Unfortunately we have specified mixed="true" in the schema definition for two elements, this created the corresponding annotation @XmlMixed in the java files.

Because of mixed=”true” the parser considered the space/newline as the different element.


Solution:

Remove the @XmlMixed from the java type file and from XSD definition if that is not required.
After removing those attributes it worked fine for us




No comments:

Post a Comment