I have the following dataweave 2.0 code in Mule 4 and I need this code in Mule 3 dataweave 1.0. Can someone help me how to convert this code to dw 1.0?
Dataweave step 1
%dw 2.0
output application/json
fun prepareList(list:Array, maxSize: Number) = if(sizeOf(list) >= maxSize )
list
else
prepareList(list ++ [(sizeOf(list) + 1) as Number],maxSize)
---
(payload map (row, index) -> ({
dummy : prepareList([],sizeOf(row)) map (irow, icounter) -> {
((row[icounter] splitBy "=")[0]) : (row[icounter] splitBy "=")[1]
}
}))
Dataweave step 2
%dw 2.0
output application/json
---
((payload reduce ((item, acc) -> acc ++ item)).*dummy map (row, index) -> ({
index : row reduce ((item2, acc2) -> acc2 ++ item2)
})).*index
Most of the operations like map, reduce, splitBy will work mostly the same in DataWeave 1.0 and probably require little or no change. The *
selector is the same.
You will have to replace if...else... by when...otherwise...
You will also have to change the declarations before the ---
divider to match the DataWeave 1.0 conventions.
Example:
%dw 1.0
%output application/json
%function prepareList(list, maxSize)
list when ( sizeOf(list) >= maxSize )
otherwise prepareList(list ++ [(sizeOf(list) + 1) as Number],maxSize)
---
You cannot. It looks similar but DW 2 is much more powerful than DW 1. It is like changing C++ to C. Looks the same but concepts are different.
It is true for opposite way. https://simpleflatservice.com/mule4/Mule3toMule4Transformation.html
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.