wso2 esb - problems with XML to JSON conversion

余生颓废 提交于 2019-12-10 19:36:39

问题


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.


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/23870347/wso2-esb-problems-with-xml-to-json-conversion

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!