Special Characters with JiBX UnMarshalling Exception

While using JiBX with Spring Web Services, following JiBX unmarshalling exception can occur while (un) marshalling the data and you special characters.

org.springframework.oxm.jibx.JibxUnmarshallingFailureException: JiBX unmarshalling exception: Error parsing document (line -1, col -1); nested exception is org.jibx.runtime.JiBXException: Error parsing document (line -1, col -1)
at org.springframework.oxm.jibx.JibxUtils.convertJibxException(JibxUtils.java:52)
at org.springframework.oxm.jibx.JibxMarshaller.convertJibxException(JibxMarshaller.java:169)

Two possible reasons behind JiBX not recongnizing the input characters are:

  • Character encoding does not include all characters of data being processed.
  • Characters in data needs to be ignored (these are the special characters to be escaped)

Following two solutions worked for above problems respectively. Defining Correct Character Encoding: Define correct character encoding for your data in following (first) line of the binding xml. <?xml version=”1.0″ encoding=”UTF-8“?> Handling Data Differently: Second possible soution is treating the data special i.e. CDATA. CDATA tag is not new for the xml technology users. With JiBX the data can be handled as CDATA through by setting the ‘style’ attribute in binding xml as “cdata”. Following example sets the value in ‘mapping’ tag. <binding xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance”          xsi:noNamespaceSchemaLocation=”file://binding.xsd“>     <namespace prefix=”ns1″ uri=”http://www.mysite.com/MySchemas” />     <mapping name=”FileRequest” ns=”http://www.mysite.com/MySchemas” class=”com.mysite.Address” ordered=”true” >         <value ns=”http://www.mysite.com/MySchemas” name=”FirstName” set-method=”setFirstName” get-method=”getFirstName” usage=”required”/>         <value ns=”http://www.mysite.com/MySchemas” field=”lastName” set-method=”setLastName” get-method=”getLastName” style=”cdata” usage=”optional”/>     </mapping> </binding>  There are few restrictions on usage of this attribute. Details can be found at JiBX: <value> Element.

Be the first to comment

Leave a Reply

Your email address will not be published.