I have the following DW 2.0 function for trimming white space on any string values in a JSON payload:
fun whiteSpaceTrimmer(item) = item match {
case is Array -> $ map whiteSpaceTrimmer($)
case is Object -> $ mapObject {
($$): $ match {
case is String -> trim($)
case is Object -> whiteSpaceTrimmer($)
case is Array -> $ map whiteSpaceTrimmer($)
else -> $
}
}
case is String -> trim($)
else -> $
}
Since it is recursive and I am not sure how deep of a nested structure it could handle before throwing an exception. Is there a limit on how many nested elements I can pass into this function? And if so is there a better approach?
Hi the current MaxExecutionStack is 256. So this means that your data structure can have as much as 255 levels of nestedness before it throws StackOverflow. If this number is not enough for you there is a System Property called com.mulesoft.dw.stacksize
that allows you to change this value.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With