Migrating Routes to XML - 7.1

author
Talend Documentation Team
EnrichVersion
7.1
EnrichProdName
Talend Big Data Platform
Talend Data Fabric
Talend Data Management Platform
Talend Data Services Platform
Talend MDM Platform
Talend Real-Time Big Data Platform
task
Data Governance > Third-party systems > Processing components (Integration) > Data mapping
Data Quality and Preparation > Third-party systems > Processing components (Integration) > Data mapping
Design and Development > Third-party systems > Processing components (Integration) > Data mapping

Migrating Routes from JavaBean to XML

Since 7.0, the Java classes and Jars support has been deprecated in Talend Data Mapper (TDM). If you have existing routes based on the JavaBean Representation, you need to migrate those to the XML Representation.

Current Java Support

The current support for Java is based on Xstream. For more information, refer to http://x-stream.github.io/.

On Input, the caller passes a JavaBean in a JavaObjectSource. The TDM Reader internally collects the JavaBean using XStream and generates SAX Events to be processed by the map's xQuery.

On Output, the TDM Java Writer also uses XStream and drops the SAX Events received from the map in a JavaBean placed in a JavaObjectResult.

Note: You can only use the current Java support in a Route, since tHMap does not support JavaObjectSource or JavaObjectResult.

Performing JavaBean to XML Serialization

To migrate your existing routes to the XML Representation in Talend Data Mapper, you need to use XStream.

Before you begin

Understand how the route differs in the previous implementation from the new implementation.
You start with the following route:
After migration, the route looks as such:
where cProcessor1p and cProcessor2p are additional camel processors.

Procedure

  1. Make a copy of the map used by the cMap component. In this example, name it as mXml.
  2. Add the XML Representation to the input and output structures used by mXml.
  3. Edit mXml and change the input and output representations to XML.
  4. Add xstream.jar, xpp3.jar, and xmlpull.jar to your configuration.
  5. Add the code to cProcessor1p. For example:
    
    org.apache.camel.Message message = exchange.getIn();
    Object payload = message.getBody();
    org.talend.transform.bean.test.Parent p = (org.talend.transform.bean.test.Parent) payload;
    
    com.thoughtworks.xstream.XStream xstream = new com.thoughtworks.xstream.XStream();
    xstream.alias("Parent", org.talend.transform.bean.test.Parent.class);
    xstream.alias("children", org.talend.transform.bean.test.Child.class);
    xstream.addImplicitCollection(org.talend.transform.bean.test.Parent.class, "children");
    String xml = xstream.toXML(p);
    
    org.apache.camel.impl.DefaultMessage in = new org.apache.camel.impl.DefaultMessage();
    in.setBody(xml);
    exchange.setIn(in);
    Note:
    • Replace org.talend.transform.bean.test with your package or classes.
    • XStream requires some aliases to generate an XML that fits the one expected by mXml.
  6. Add the code to the cProcessor2p. For example:
    
    org.apache.camel.Message message = exchange.getIn();
    Object payload = message.getBody();
    String xml = (String) payload;
    System.out.println(xml);
    		
    com.thoughtworks.xstream.XStream xstream = new com.thoughtworks.xstream.XStream();
    xstream.alias("Parent", org.talend.transform.bean.test.Parent.class);
    xstream.alias("children", org.talend.transform.bean.test.Child.class);
    xstream.addImplicitCollection(org.talend.transform.bean.test.Parent.class, "children");
    org.talend.transform.bean.test.Parent p = (org.talend.transform.bean.test.Parent) xstream.fromXML(xml);
    org.apache.camel.Message in = new org.apache.camel.impl.DefaultMessage();
    in.setBody(p);
    exchange.setIn(in);
    Note: Replace org.talend.transform.bean.testwith your package or classes.