0

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
2
  • Did you try to change the encoding to UTF-8? <?xml version="1.0" encoding="utf-8"?> Commented Apr 11, 2023 at 9:31
  • @Marko Marinkovic Yes. I tried . I send data as <?xml version="1.0" encoding="utf-8"?> I am not getting this error. But my use case is to use utf-16 as encoding in input data Commented Apr 11, 2023 at 9:40

2 Answers 2

1

The input XML declares to be encoded in UTF-16 which uses 2 bytes per character but actually uses only 1 byte per character, so the input data is not valid.

Sign up to request clarification or add additional context in comments.

2 Comments

The same input working fine with mule 3 apps. Only seeing this issue with mule 4 application
Maybe Mule 3 does not validate the encoding in the XML declaration. Clearly Mule 4 is validating it.
0

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")

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.