<logger message="#[payload]"/> <set-variable variableName="httpResponseStatus" value="#[attributes.statusCode]"/>
Introduction to Mule 4: DataWeave Expression Language
Standard Support for Mule 4.1 ended on November 2, 2020, and this version of Mule will reach its End of Life on November 2, 2022, when Extended Support ends.
Deployments of new applications to CloudHub that use this version of Mule are no longer allowed. Only in-place updates to applications are permitted.
MuleSoft recommends that you upgrade to the latest version of Mule 4 that is in Standard Support so that your applications run with the latest fixes and security enhancements.
In Mule 3, you must learn both the Mule Expression Language (MEL) and DataWeave. MEL forces you to convert your payloads from binary data (such as XML or JSON documents) into Java objects so that you can write expressions that access that data, for example, when routing to a specific location.
In Mule 4, DataWeave is the default expression language. Combined with the built-in streaming capabilities, this change simplifies many common tasks:
Events can be routed based on payload data, without requiring conversion to Java objects.
Binary data can easily be queried from an expression anywhere in your flow, for example, when logging.
Streaming now happens transparently. You no longer need to worry about larger-than-memory data streams or about consuming a stream twice.
DataWeave 2.0 also features many improvements, which are covered in the DataWeave 2.0 section.
At the core, expressions continue to work as before. You can use them to extract data, log data, or make decisions about where to route data. And like MEL, the syntax to access properties in your data is very simple.
Unlike MEL, you can use DataWave to easily access data anywhere in your flow without concern for transforming it into intermediate objects. Consider this example in Mule 3:
<http:listener path="/hello"/> <!-- receives a JSON HTTP Body --> <json:json-to-object/> <!-- convert to Java objects --> <choice> <!-- route data based on the data --> <when expression="#[payload.customer == 'Acme, Inc']"> <!-- do some logic --> </when> </choice>
In Mule 4, you no longer need to convert JSON to an intermediate format. You can simply access the data directly through expressions without losing the original underlying data, and Mule 4 handles all data streaming and random access transparently for you.
<http:listener path="/hello"/> <!-- receives a JSON HTTP Body --> <choice> <!-- route data based on the data --> <when expression="#[payload.customer == 'Acme, Inc']"> <!-- do some logic --> </when> </choice>