%dw 2.0
output application/json
---
{
"onNull": []
reduce ((item, accumulator) -> item ++ accumulator)
then ((result) -> sizeOf(result))
onNull "Empty Text"
}
DataWeave
onNull
onNull<R>(previous: Null, callback: () -> R): R
Executes a callback function if the preceding expression returns a null
value and then replaces the null
value with the result of the callback.
Introduced in DataWeave version 2.4.0.
Parameters
Name | Description |
---|---|
|
The value of the preceding expression. |
|
Callback that generates a new value if |
Example
This example shows how onNull
behaves when it receives a null
value.
Source
Output
{
"onNull": "Empty Text"
}
Json
onNull<T>(previous: T, callback: () -> Any): T
Helper function that enables onNull
to work with a non-null value.
Introduced in DataWeave version 2.4.0.