Uploaded image for project: 'Camel'
  1. Camel
  2. CAMEL-13282

Can't use validation of JaxbDataFormat of non Root JAXB Elements

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 2.23.1
    • 2.24.0, 3.0.0-M2, 3.0.0
    • camel-jaxb
    • None
    • Unknown

    Description

      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

      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:

      <element name="myElement" type="tns:myElementType"/>
      <complexType name="myElementType">
      <!-- your type definition here -->
      </complexType>
      

      instead you should write

      <element name="myElement>
        <complexType>
         <!-- your type definition here -->
        </complexType>
      </element>
      

      Attachments

        Issue Links

          Activity

            People

              acosentino Andrea Cosentino
              michael.lueck Michael Lück
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 10m
                  10m