JAXB Unmarshall Created an Empty Object JAXB Unmarshall Created an Empty Object xml xml

JAXB Unmarshall Created an Empty Object


JAXB by default silently ignores errors. I cannot see any reason why this is the default configuration. Try adding this code to throw an exception if something goes wrong.

unmarshaller.setEventHandler(    new ValidationEventHandler() {        @Override        public boolean handleEvent(ValidationEvent event ) {            throw new RuntimeException(event.getMessage(),                                       event.getLinkedException());        }});


Recently I had similar kind of issue, and could able to fix it up as below:

1) Fixup the xsd file.In my case I've ensured that all complex elements in xsd refering to their corresponding type using ref attribute, instead of declaring them with type attribute.

I've verified whether my xsd proper or not by creating an xml file from XML Schema file option in Eclipse.

Before the fix, the root element in the xml file was empty. After fixing the xsd the xml was got created properly with some sample values.

2) clean and re-buildIt's mandatory to clean before re-generating the classes.


Just want to add that when Axis2 is used together with Rampart (SOAP Body encryption) and JAXB, this issue occurs always.

See for details: AXIS2-4981