Nav

Troubleshooting in DataWeave

This document lists common error messages, what these mean and how to resolve them.

Cannot coerce :binary to :object

It means that DataWeave is trying to transform a binary value to an object, which isn’t allowed.

Cause: One possible case is that DataWeave is reading the content as binary as it was an 'InputStream' or 'Byte array' and its mime type is not set. In this scenario DataWeave defaults to Java reader. If you look at the Info log it would display something like this:

MimeType was not resolved '*/*' delegating to Java.

Solution : Validate that the mimeType is set. For example verify that if your data source has a mime-type field, its value is set, or if the value is set through a set-payload or set-variable component, then the mime-type property was defined in it.

Cannot coerce :string to :object

It means that DataWeave is trying to transform a string value to type object.

Cause: Same as Cannot coerce :binary to :object, this may be a mime-type problem.

Cause: If the value is an XML, this may be caused by an empty tag. By default the XML reader reads

Take the following example:

Input

         
      
1
<user></user>
Transform
payload.user.name

The above script fails with the error Cannot coerce :string to :object

Reason: As you can see the input xml is an empty xml tag, so the expression payload.user returns an empty string. Then DataWeave tries to apply the 'name' selector over a string, which raises an exception.

Solution: The XML reader has a configuration property named 'nullValueOn'. This property can be set to "blank" or "empty", which can fix this issue. To set this property see To Define Input and Output Structure of a Transformation.