Uploaded image for project: 'SwitchYard'
  1. SwitchYard
  2. SWITCHYARD-2852

SY: JAXB Marshalling should also work without @XmlRootElement Annotation

    Details

    • Type: Enhancement
    • Status: Resolved (View Workflow)
    • Priority: Major
    • Resolution: Done
    • Affects Version/s: 2.0
    • Fix Version/s: 2.1.0
    • Component/s: extensions
    • Labels:
      None

      Description

      JBFPL-281

      Copied description from JBFPL-281:
      As already mentioned here: https://access.redhat.com/solutions/1258653 it's necessary to add "@XmlRootElement" to the JAXB Classes. This should also work without the @XmlRootElement annotation. Switchyard JAXBMarshallTransformer to detect if the message is not a @XmlRootElement annotated object and to instead automatically wrap the class in a JAXBElement using the to/from for the namespace.
      This appears to be related to the following bug where the behavior was changed from an implementation that's similar to what you are suggesting to the current implementation:
      https://issues.jboss.org/browse/SWITCHYARD-1290
      https://developer.jboss.org/thread/220794?tstart=0
      https://github.com/jboss-switchyard/core/commit/71a30b6c0503c9c9f7625c4c3c46c48871d3b70b
      I understand this was changed because of an issue processing doc literal unwrapped messages which required the explicitness of the element name from @XmlRootElement and namespace from package-info.java. However, it seems limiting to not allow non-@XmlRootElement to be used
      As an example i took the https://github.com/jboss-switchyard/quickstarts/tree/1.1.1-p9/transform-jaxb project and removed the annotations in the "Order" and "OrderAck" classes.
      Now a call to the SOAP Service thows the (expected) exception:
      ...
      Caused by: javax.xml.bind.MarshalException
      with linked exception:
      [com.sun.istack.SAXException2: Marshalling von Typ "org.switchyard.quickstarts.transform.jaxb.OrderAck" als Element ist nicht möglich, weil eine @XmlRootElement-Annotation fehlt]
      at com.sun.xml.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:326) [jaxb-impl-2.2.5-redhat-5.jar:2.2.5-redhat-5]
      at com.sun.xml.bind.v2.runtime.MarshallerImpl.marshal(MarshallerImpl.java:251) [jaxb-impl-2.2.5-redhat-5.jar:2.2.5-redhat-5]
      at javax.xml.bind.helpers.AbstractMarshallerImpl.marshal(AbstractMarshallerImpl.java:95) [jboss-jaxb-api_2.2_spec-1.0.4.Final-redhat-2.jar:1.0.4.Final-redhat-2]
      at org.switchyard.transform.jaxb.internal.JAXBMarshalTransformer.transform(JAXBMarshalTransformer.java:80) [switchyard-transform-1.1.1-p9-redhat-1.jar:1.1.1-p9-redhat-1]
      ... 180 more
      Caused by: com.sun.istack.SAXException2: Marshalling von Typ "org.switchyard.quickstarts.transform.jaxb.OrderAck" als Element ist nicht möglich, weil eine @XmlRootElement-Annotation fehlt
      at com.sun.xml.bind.v2.runtime.XMLSerializer.reportError(XMLSerializer.java:249) [jaxb-impl-2.2.5-redhat-5.jar:2.2.5-redhat-5]
      at com.sun.xml.bind.v2.runtime.ClassBeanInfoImpl.serializeRoot(ClassBeanInfoImpl.java:337) [jaxb-impl-2.2.5-redhat-5.jar:2.2.5-redhat-5]
      at com.sun.xml.bind.v2.runtime.XMLSerializer.childAsRoot(XMLSerializer.java:494) [jaxb-impl-2.2.5-redhat-5.jar:2.2.5-redhat-5]
      at com.sun.xml.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:323) [jaxb-impl-2.2.5-redhat-5.jar:2.2.5-redhat-5]
      ... 183 more
      ...
      Shouldn't the JAXBMarshalTransformer use the generated ObjectFactory to create a "JAXBElement"-Wrapped instance using: "public JAXBElement<OrderAck> createOrderAck(OrderAck value)" - (it does not)?

        Gliffy Diagrams

          Attachments

            Issue Links

              Activity

                People

                • Assignee:
                  tcunning Thomas Cunningham
                  Reporter:
                  tcunning Thomas Cunningham
                • Votes:
                  0 Vote for this issue
                  Watchers:
                  1 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved: