Search code examples
muledataweavemulesoftutf-16mule4

Unable to transform utf-16 xml in Mule


I am receiving an XML input in utf-16 format (<?xml version="1.0" encoding="utf-16"?>). While transforming this data in Mule I am getting this error:

Declared encoding 'UTF-16' uses 2 bytes per character; but physical encoding appeared to use 1; cannot decode
 at [row,col {unknown-source}]: [1,40], while reading `payload` as Xml.
 [row,col]: [1,40]" evaluating expression: "%dw 2.0
output application/json
---
payload"

I am able to perform this transform the DataWeave playground (https://dataweave.mulesoft.com/learn/#playground) without any issues.

Input payload

<?xml version="1.0" encoding="utf-16"?>
<Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <Body>
        <DOC_POST>
            <ACCOUNT>
                <Item>
                    <PLANT>1000</PLANT>
                </Item>
           </ACCOUNT>
  
        </DOC_POST>
    </Body>
</Envelope>

Anypoint Studio version: 7.10.0 Mule runtime: 4.3.0

Transformation:

%dw 2.0
output application/json
---
payload

Solution

  • I am able to fix this issue by updating the HTTP listener which is receiving the input XML. I have updated the mime type to text/plain while receiving the data and then use transform to convert it in to XML. This XML will be of UTF-8 format.

    %dw 2.0

    output application/xml

    read(payload, "application/xml")