{
orderStatus: "complete" when flowVars.purchaseOrderStatus == "C" otherwise "incomplete"
}
Migrating from DataWeave version 1 to 2
Standard Support for Mule 4.1 ended on November 2, 2020, and this version of Mule reached its End of Life on November 2, 2022, when Extended Support ended. 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. |
DataWeave Header Content
Most of the header directives have been changed in DataWeave. The %dw
directive is an exception. In most cases, MuleSoft removed the %
, and in some cases the keyword is shortened.
DataWeave 1.0 | DataWeave 2.0 | |
---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Flow Controls
Flow control changed somewhat in DataWeave 2.
When Otherwise
The when otherwise
statement is replaced by if else
, for example:
{
orderStatus: if(vars.purchaseOrderStatus == "C") "complete" else "incomplete"
}
Pattern Matcher
Pattern matching changed in DataWeave 2. It adds the keyword case
and else
(instead of default
). You also no longer separate cases with commas (,
) since they are now explicitly separated by the case
keyword.
'world' match {
:string -> true,
default -> false
}
'world' match {
case is String -> true
else -> false
}
For type pattern matchers, the is
keyword needs to be set.
Type References
The :
was removed from the type references and are now all camel case, so :string
is now String
Object Coercion
In DataWeave 1.0, selecting a key-value pair from an object required you to do something like this:
%var payload = {a: 1, b:2}
---
payload.a as :object
The DataWeave 1.0 expression above returns {a:1}
. Because this is a coercion, it is also included in the auto-coercion mechanism and generates undesired or unexpected results.
In DataWeave 2.0, the coercion is removed, and a new selector (&
) is introduced to select key-value pair parenthesis.
var payload = {a: 1, b:2}
---
payload.&a
This expression also returns {a:1}
.