Contact Us 1-800-596-4880

Mule Data Types

Mule runtime engine uses a typed data structure called TypedValue that centralizes data access across different components. This data structure provides access to both the actual data and its data type. The data type consists of two values, the MIME type and the encoding of the data.

Input Data

Mule stores all variables and the payload using the TypedValue data structure. Also, operations like List from the Anypoint Platform File Connector return their results as TypedValue instances, enabling DataWeave to list different types of files (JSON, XML, CSV, and so on) to read.

Output Data

DataWeave always outputs a TypedValue instance. DataWeave decides what writer to use based on the data type of the TypedValue instance. However, you can manually specify the data type in a DataWeave script by using the output directive. If the script that Mule is executing is assigned to a message processing field, Mule informs DataWeave which type of data to expect type based on the metadata of that field. For example, if the data type is a Plain Old Java Object (Pojo), then DataWeave knows not only which class to instantiate but also that it must use the Java writer to generate the output.

How DataWeave Uses Mule Data Types

DataWeave uses the data type contained in the TypedValue instance to determine which reader to use, based on the MIME type, and how to configure that reader (encoding, reader properties), based on the MIME type properties. When DataWeave cannot determine the data type, it follows this procedure:

  1. Verifies which input types the script is using.

    If all inputs are compatible or of the same data type, DataWeave uses that data type. For example, if the script contains <set-payload value="#[payload.someValue]/> DataWeave examines the data type of the payload and, if the payload is JSON, DataWeave uses the JSON writer. If there is more than one input in the script and they are from different data types, DataWeave throws an error.

    For example, if the script contains <set-payload value="#[payload.someValue ++ vars.myVar]/>, in which vars.myBar is of type XML and payload is of type JSON, DataWeave throws an error. In some cases, specifically when working with XML, an expression in a Set payload operation fails because it generates an invalid XML structure.

  2. If no input is used, DataWeave uses the Java writer.

    For example, when DataWeave reads the script <set-payload value="#[\{a: true}]/>, it uses the Java writer to output a java.util.Map object with an entry containing ("a", true).

    For the Logger message processor, DataWeave has a special feature to avoid errors when creating the output. First, DataWeave tries to determine which input types the script is using, and then it uses the corresponding writer to generate the output. If DataWeave fails because the writer cannot create that data structure, then DataWeave uses the DataWeave writer, which can output any possible data structure.