简体   繁体   中英

How to use Mule's XML-to-Object transformer?

What are the steps which should be done? What should be present in the driver class? How should I create the POJO with which to map the XML to? How should I configure the transformer?

you can use a driver class like Xpp3driver

eg.

the flow would look something like

<flow name="mulexmlvalFlow2" doc:name="mulexmlvalFlow2">
        <http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8082" doc:name="HTTP" path="XmlToObj"/>
        <mulexml:xml-to-object-transformer doc:name="XML to Object" driverClass="com.thoughtworks.xstream.io.xml.Xpp3Driver">
            <mulexml:alias name="Abc" class="a.b.c.Abc" />        
        </mulexml:xml-to-object-transformer>
        <component class="Test1" doc:name="Java"/>
</flow>

http request

http://localhost:8082/XmlToObj

headers Content-Type application/xml post data

<Abc><def>ggggg</def><ghi>hhhhh</ghi></Abc>

ABC class

package a.b.c.Abc;
import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement(name = "Abc")
public class Abc{
private String def;
private String ghi;

public Abc() {
}

public String getDef() {
    return def;
}
public void setDef(String def) {
    this.def = def;
}
public String getGhi() {
    return ghi;
}
public void setGhi(String ghi) {
    this.ghi = ghi;
}

}

Class Test1 (component)

public class Test1 {

    public Object receive(Abc abc) throws Exception {
        System.out.println(abc);
        return "Success";
    }

}

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