Working with Java sample data objects - 7.3

Talend Data Mapper User Guide

Version
7.3
Language
English
Product
Talend Big Data Platform
Talend Data Fabric
Talend Data Management Platform
Talend Data Services Platform
Talend MDM Platform
Talend Real-Time Big Data Platform
Module
Talend Studio
Content
Design and Development > Designing Jobs
Last publication date
2023-01-05

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 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.