Debugging DataWeave output in Studio

One of the greatest features of Anypoint Studio is the Visual Design Debugger and often times you want to see the payload as a string during debugging. Generally using #[payload:java.lang.String] or #[message.payloadAs(java.lang.String)] does the trick. But when it comes to DataWeave, those methods don’t work if the output is anything other than ‘application/java‘ due to the nature of the payload data type:

DataWeave Output Payload
com.mulesoft.weave.mule.WeaveMessageProcessor.WeaveOutputHandler

So the question is, “How do you debug the output coming out of DataWeave?” In this post, I’ll cover that question with a couple scenarios. Keep in mind that these scenarios are just workarounds. It would be ideal to just debug the flow without adding in additional components.

application/json

If your output is set to application/json, you can drop in a JSON to Object transformer after the Transform Message component before you start debugging. In doing so, you can view the JSON that’s returned by DataWeave as you step past the component. You will of course need to remove that component after debugging unless you need the data in that format.

JSON to Object
JSON to Object

application/xml

If your output is set to application/xml, before you start debugging, you can drop in a XML to DOM transformer after the Transform Message component. Once you step past the component, you can use Evaluate Mule Message (Shift + Command + I) and enter the expression #[payload:java.lang.String] to see the resulting XML from DataWeave. Again, you’ll need to remove that component after debugging unless you need the data in that format.

XML to DOM
XML to DOM

application/csv

If your output is set to application/csv, before you start debugging, you can drop in an Object to String transformer after the Transform Message component. Unlike the application/json or application/xml, this will automatically show you the expected data of the payload in the Mule Debug window. Again, you’ll need to remove that component after debugging unless you need the data in that format.

Summary

As you can see, the general workaround is drop in a component that converts the DataWeave output to an alternative format. By doing so, you can view the payload in Mule Debugger or use the #[payload:java.lang.String] method. Hopefully the next version of DataWeave and the Transform Component will make this easier.


Posted

in

by

Comments