You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@camel.apache.org by "Andrea Cosentino (JIRA)" <ji...@apache.org> on 2019/03/15 12:58:00 UTC

[jira] [Resolved] (CAMEL-13282) Can't use validation of JaxbDataFormat of non Root JAXB Elements

     [ https://issues.apache.org/jira/browse/CAMEL-13282?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Andrea Cosentino resolved CAMEL-13282.
--------------------------------------
    Resolution: Fixed

> Can't use validation of JaxbDataFormat of non Root JAXB Elements
> ----------------------------------------------------------------
>
>                 Key: CAMEL-13282
>                 URL: https://issues.apache.org/jira/browse/CAMEL-13282
>             Project: Camel
>          Issue Type: Bug
>          Components: camel-jaxb
>    Affects Versions: 2.23.1
>            Reporter: Michael Lück
>            Assignee: Andrea Cosentino
>            Priority: Major
>             Fix For: 3.0.0, 2.24.0, 3.0.0-M2
>
>          Time Spent: 10m
>  Remaining Estimate: 0h
>
> 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
>  message.
> 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 |https://github.com/apache/camel/pull/2800]
> *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:
> {code:xml}
> <element name="myElement" type="tns:myElementType"/>
> <complexType name="myElementType">
> <!-- your type definition here -->
> </complexType>
> {code}
> instead you should write
> {code:xml}
> <element name="myElement>
>   <complexType>
>    <!-- your type definition here -->
>   </complexType>
> </element>
> {code}



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)