简体   繁体   中英

Mule ESB JAXB XML To Object Transformer Better Way?

Mule 3.3 can automatically unmarshall an XML string to an object using JAXB given that:
1. you first register your jaxb annotated classes with spring. 2. there is a component that requires such type as input

So I have managed to do the transformation, but I had to create a "DumbTransformer" that does nothing. It has a method that returns the same object it receives. I need it in order to trigger the XML to Object conversion so that I can further process the message.

Flow Example:

<spring:beans>
    <spring:bean id="dumbTransformer" class="foo.bar.DumbTransformer"/>
</spring:beans>

<flow name="main" doc:name="main">
    <vm:inbound-endpoint path="in" doc:name="VM" />
        <component doc:name="Java">
            <spring-object bean="dumbTransformer"/>
        </component>
        <splitter expression="#[payload.items]" doc:name="Split Items"/>
    <logger message="#[payload]" level="INFO" doc:name="Log Item"/>
    <vm:outbound-endpoint path="out" doc:name="VM" />
</flow>

DumbTransformer.java

package foo.bar;

@ContainsTransformerMethods
public class InvoiceUnmarshaller extends AbstractTransformer {

    @Transformer
    public MyJaxbAnnotatedClass foo(@Payload MyJaxbAnnotatedClass i) {
        return i;
    }

}

Is there a way to acomplish this without having to create such DumbTransformers?

Thanks.

As you guessed it, the JAXB deserialization doesn't occur because there is no component to satisfy:

  1. there is a component that requires such type as input

So what if you had an auto-transformer to do just that:

<auto-transformer returnClass="foo.bar.MyJaxbAnnotatedClass" />

The Mule XML Module provides OOTB a JAXB Transformer . I would rather leverage mule capabilities whenever possible rather than writing custom code

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM