WSO2 EI使用Json有效负载构造XML请求

问题描述 投票:1回答:1

如何使用下面的JSON构建XML有效负载:

{
    "Request": {
        "lineCode": "00060139A",
        "lineSerial": "1",
        "lineCurrency": "MNT",
        "revolvingLine": "Y",
        "lineExpiryDate": "2019-12-25",
        "availabilityFlag": "Y",
        "limitAmount": "1000.00",
        "nettingRequired": "N",
        "unAdvised": "N",
        "liaBBr": "101",
        "branchId" : "101",
        "lmtAmtBasics": "L",
        "funded": "N",
        "liaBID": "l",
        "description": "desc",
        "udfDetails": [
            {
                "fieldName": "BONEV",
                "fieldValue": "0"
            },
            {
                "fieldName": "test",
                "fieldValue": "1"
            }
        ]
    }
}

它包含json数组,udfDetails,

我想在下面建立xml,我尝试了迭代和foreach,但它通过udf参数循环了整个请求(在这种情况下为2次):

 <Cust-Account-Full>
  <SWEEP_IN>N</SWEEP_IN>
               <SWEEP_OUT>N</SWEEP_OUT>
               <SPDANLSYS>N</SPDANLSYS>
               <AUTOPROVREQ>N</AUTOPROVREQ>
               <!--FACILITY SALGAH-->
               <LINEIDTSLIST>01110764A1</LINEIDTSLIST>
               <UDFDETAILS>
                  <FLDNAM>TERM_DEPOSIT_LINK</FLDNAM>
                  <FLDVAL>No</FLDVAL>
               </UDFDETAILS>
               <UDFDETAILS>
                  <FLDNAM>Bonev</FLDNAM>
                  <FLDVAL>0</FLDVAL>
               </UDFDETAILS>
               <UDFDETAILS>
                  <FLDNAM>test</FLDNAM>
                  <FLDVAL>1</FLDVAL>
               </UDFDETAILS>
            </Cust-Account-Full>
wso2 wso2esb wso2-am wso2carbon wso2ei
1个回答
0
投票

您可以部署以下代理,以将上述JSON转换为XML。

<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
       name="jsonToXmlProxy"
       startOnLoad="true"
       statistics="disable"
       trace="disable"
       transports="http,https">
   <target>
      <inSequence>
         <property name="messageType" scope="axis2" value="application/xml"/>
         <respond/>
      </inSequence>
   </target>
   <description/>
</proxy>

messageType属性可用于XML到JSON和JSON到XML的转换。下面的示例将XML转换为JSON。

<property name="messageType" scope="axis2" value="application/xml"/>

当您调用jsonToXmlProxy时,将得到以下响应。

<jsonObject>
    <Request>
        <lineCode>00060139A</lineCode>
        <lineSerial>1</lineSerial>
        <lineCurrency>MNT</lineCurrency>
        <revolvingLine>Y</revolvingLine>
        <lineExpiryDate>2019-12-25</lineExpiryDate>
        <availabilityFlag>Y</availabilityFlag>
        <limitAmount>1000.00</limitAmount>
        <nettingRequired>N</nettingRequired>
        <unAdvised>N</unAdvised>
        <liaBBr>101</liaBBr>
        <branchId>101</branchId>
        <lmtAmtBasics>L</lmtAmtBasics>
        <funded>N</funded>
        <liaBID>l</liaBID>
        <description>desc</description>
        <udfDetails>
            <fieldName>BONEV</fieldName>
            <fieldValue>0</fieldValue>
        </udfDetails>
        <udfDetails>
            <fieldName>test</fieldName>
            <fieldValue>1</fieldValue>
        </udfDetails>
    </Request>
</jsonObject>
© www.soinside.com 2019 - 2024. All rights reserved.