Tuesday, March 17, 2009

JAXB Debugging Unmarshalling

When you need to debug JAXB2 unmarshalling issues, try the following:

1) Set the system property "jaxb.debug" to "true"
2) Set the event handler on the unmarshaller which will print out the errors to System.out as follows:
um.setEventHandler(new javax.xml.bind.helpers.DefaultValidationEventHandler());

Additional note

If you start seeing errors such as the sax parser not finding schema types, then look at the stack trace. If it shows com.sun.xerces (which is Sun JDK internal port of Xerces), then you will need to
either a) endorse the Xerces libraries or b) a system property


On 26.09.2006, at 15:48, Michael Glavassevich wrote:

> Hi Simon,
> You weren't actually using Xerces when you ran your test. The
> com.sun.org.apache.xerces.internal.* packages originate from Sun's
> Java 5.
> Regardless of whether there are schema locations in the document or
> not it
> doesn't seem to call the LSResourceResolver. This is probably one
> of many
> bugs which we've fixed (in the last three years) or one that never
> existed
> since the Validator implementation in Xerces is significantly
> different
> than the one included in Java 5.
> There's one Java 5 bug [1] in particular which prevents the
> SchemaFactory's factory finder from finding the implementation on the
> classpath. If you had xercesImpl.jar in your classpath this would
> explain
> why you got the JDK default instead. To select Xerces'
> SchemaFactory you
> can set a system property -Djavax.xml.validation.SchemaFactory:
> http://www.w3.org/2001/
> XMLSchema=org.apache.xerces.jaxp.validation.XMLSchemaFactory
> . Putting the xml-apis.jar which accompanies Xerces in your JDK's
> endorsed
> directory [2] works as well.

No comments: