Java Sample Data Objects - 6.3

Talend Data Mapper User Guide

EnrichVersion
6.3
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
Design and Development
EnrichPlatform
Talend Studio

You can create sample documents from Java object instances so that you can test maps that use Java objects as input. These documents are stored as XML as defined in the XStream project's default serialization. Well, almost the default serialization, the only difference is that it specifies the ID_REFERENCES option so that the object graph is preserved in the case of inter-object references.

You can produce these XML-serialized Java objects in the following ways:

  • As an Output - If you have a map that writes to the desired Java object, this is the easiest way to go. Simply test run the map in the designer to a sample output document. Do this by selecting the Test Run to Sample Document in either the Test Run button's menu or the Test menu on the main menu bar. This will produce the XML document and associate it with the output structure of the map.

  • Using the Runtime API - In the Runtime API use the RuntimeEngine.addSampleData() method to add a specified Java object instance to the desired structure's sample documents. There is an example program for this in the Java folder of the examples project called com.mycompany.accting.AddJavaObjectSample. You can modify this program to create your object, and then execute it as a Java application within the Data Mapper. In order to execute it, you will need to provide the JAR file containing the Runtime API in your classpath. You will also need to specify the ODT_DEV_WORKSPACE Java system property (you can do this in your Launch Configuration) to be the file path or URL (using the file scheme) of the Eclipse workspace containing the project that gets the sample document.

  • Using your own Standalone Code - The following snippet of code can be used to produce the sample document; this depends on the some XStream classes, but has no other dependency.

    		HierarchicalStreamWriter javaWriter;
    		StringWriter sw = new StringWriter();
    		javaWriter = new PrettyPrintWriter(sw);
    
    		XStream xsShow = new XStream(null);
    		xsShow.setMode(XStream.ID_REFERENCES);
    		xsShow.marshal(yourObject, javaWriter);
    		javaWriter.flush();

    You put the string into a file and then copy the file into the Sample Data folder corresponding to your Java structure in the workspace.