How to convert string to message type, for use in XML2JSON

We need to convert the java callout response XML to JSON.

When we tried it throws below error. Please suggest as how to resolve?

{"fault":{"faultstring":"XMLToJSON[XML-JSON-Response]: String can not be assigned to message type.","detail":{"errorcode":"steps.xml2json.InCompatibleTypes"}}}
0 1 746
1 REPLY 1

Try this:

<AssignMessage name='AM-1'>
  <AssignTo createNew='true' transport='http' type='response'>tmpMessage</AssignTo>
  <IgnoreUnresolvedVariables>false</IgnoreUnresolvedVariables>
  <Set>
    <Payload contentType='application/xml'>{my_string_variable}</Payload>
  </Set>
</AssignMessage>

It's kinda bothersome that XML2JSON doesn't accept a string as input. But it's easy to work around that constraint.

If you don't like contriving a new message in policies, you can have the Java callout create a Message type object and set it in your Java code. That Message object would contain the status code, the headers (including content-type), and the payload.