Reading Time: 6 minutes

One aspect of DataMapper that makes it a grate integration tool is its ability to do mappings involving complex and different data structures (XML, Json, POJOs, CSV, Excel files and more). One feature that is really attractive is the possibility to test your mappings without the need to launch your Mule application, so that you can provide sample input data and preview what the result of the DataMapper will be.

After reading this post you should be able to:

  • Understand how to add and use Input Arguments
  • Test your mappings with the Preview Functionality
  • Create an input POJO to test the mapping

What are Input Arguments?

latest report
Learn why we are the Leaders in management and

The DataMapper component maps/transforms anything that comes in the Mule flow payload into another format. But what happens when you want to enrich the contents of the payload, by sending other values that should be used as input for the mapping? For these cases you can use Input Arguments by defining a name and a value. The value can be a literal or any Mule Expression that returns a native value (String, Integer, Long, Double, …).

Adding Input Arguments to your DataMapper Component

Let's start with a simple mule flow that has a DataMapper component. For simplicity we will start with a VM inbound endpoint (where the mapping input POJO will be received), a DataMapper component and a file outbound endpoint to save the output into a CSV file.

Now lets add the input arguments. If not done yet, first run the DataMapper wizard. In this case I created a Pojo to CSV mapping providing a sample java class and a sample csv file (download the sample Studio project with both files from here). Input arguments are created from the mapping editor.

Right click on the Input arguments label and click on Add input argument. Complete all details in the editor:

  • Name: Is the name used to display the input argument in the mapping editor
  • Type: Choose the variable type of the argument
  • Mule expression: Literal or expression that will generate the value in runtime

Previewing your mappings

DataMapper comes with a preview functionality that allows you to run the mapping without the need of starting the Mule application. As there is no runtime, you need to provide the input values yourself. In order to do this you should go to the preview tab (1) and then provide values for the input pojo (2) and the input arguments (3).

Sampling the input Pojo

  1. Create a groovy script that builds, set values and return an instance of your java object
  2. Choose the groovy script you created by clicking the button (2)

Sample Groovy Script used in this example (Please forgive my bad groovy skills!)

Providing values to Input arguments

  1. Click on the Input Arguments button (3)
  2. Select the input argument from the table list and provide a value

The only thing that's left now is to Run the Mapping and check the results in the Text pane!

That was all. You can use the preview functionality for other types too, so I invite you to try them and get back to me with your feedback!