When a JAXB class that is created or generated has no @XmlRootElement
annotation JaxbDataFormat would try to find a ObjectFactory method which
can create a JAXBElement for the type of the object. It would then use
the JAXBElement to marshal the object.
While trying to find the objectFactory and to call the appropriate
method it would catch ALL Exceptions that are thrown and just logs a
While I don't see why an Exception should only be logged here, this especially
breaks when the exception is thrown due to a validation error. Because
the calls to the marshal operation will throw an MarshalException in
that case which would be caught by the catch block. In other cases where
no object factory is used but JAXB classes with XmlRootElement
Annotations or JAXBElements are used the MarshalExceptions will be
thrown and the doMarshal method will be left.
I already created a PR on github for this: PR2800
Workaround: If someone is experiencing this problem the first thing to check whether is it possible to make the JAXB Class have the @XmlRootElement Annotation. In that case you won't experience any problems.
Especially when the classes are generated from XSD you may either use an separate binding to add the annotation or you may create the element definitions in the xsd using an anonymous inline complexType/simpleType that extends your desired type.
In my case the @XmlRootElement annotation was not added because i used the definition as follows:
instead you should write