Debugging JAXB unmarshalling issues

JAXB appears to fail silently in some cases if the XML it’s attempting to unmarshall to mapped classes doesn’t have the necessary mapped properties.

You can get additional output by adding the following:


– displays information during JAXB initialization

Before you call unmarshall() on your Unmarshaller, call setEventHandler() and add a DefaultValidationEventHandler as follows:

Unmarshaller um = jaxbContext.createUnmarshaller();
um.setEventHandler(new javax.xml.bind.helpers.DefaultValidationEventHandler());

– this will output additional failure information about missing mappings for xml elements, useful if your mapped class ends up with missing values.

Things you always forget: XML Character Entities

Certain characters break XML or need to be escaped in HTML so they are rendered literally and not interpreted themselves as markup. There’s a few predefined character entities that are commonly used:

  • &lt;      :     <
  • &gt;     :     >
  • &amp; :    &

For other characters though, you sometimes need to use their Unicode encoded value. For example to literally display { and } in a JSP or JSF page (since they are used in EL syntax ${} and #{} ), you can use their unicode values like this:

  • &#x007b;     :     {
  • &#x007d;     :     }

There’s many unicode ref charts online, here’s one that I’ve used: