I'm using WSO2 ESB 4.8.0 and I have the following problems converting an xml (from an xslt output) to a json:
strings with numbers automatically get converted as integer elements: "orderId": 10000 ( I want it to be string "orderId": "10000" )
xml list come as json object if there is one element and as json array if more than one element is present..How can I tell the converter "this particular item must always be an array" ?
I'm using xslt to build the xml (as I have variuos xml to merge from some external system calls) and then use the property messageType application/json.
I can't use the payloadFactory since I have some logics to implement and use the script mediator with javascript instructions semms to me like a worst solution.
Thanks in advance.
To get this done you can change the JSON Message Formatters.
Go to [ESB Home]/repository/conf/axis2/axis2.xml.
Change the JSON Message Formatters
instead of JsonStreamFormatter use org.apache.axis2.json.JSONMessageFormatter
<!--messageFormatter contentType="application/json"
class="org.apache.synapse.commons.json.JsonStreamFormatter"/-->
<messageFormatter contentType="application/json"
class="org.apache.axis2.json.JSONStreamFormatter"/>
Note. here all values would be strings.
First, notice that several conversion options are on the desk to map between XML and JSON. I would recommend to use another xslt, to map previous to be sent between your xml and json, and then send the json. Maybe, even you can put all this logic into a sequence, and call that sequence from all the points you need.
For an example of xslt, see http://www.bramstein.com/projects/xsltjson/.
HTH.