【问题标题】:Converting One Data Type Object to another Data Type Object in WSO2 Config Lang在 WSO2 Config Lang 中将一个数据类型对象转换为另一种数据类型对象
【发布时间】:2018-11-09 12:05:06
【问题描述】:

我正在尝试将一个 json 有效负载转换为另一个,我尝试使用 DataMapper 但输出有效负载与输入有效负载不匹配,因此我无法映射这两个数据。

我尝试了丰富的调解员,但我似乎无法通过。

输入json

{
    "requestID": "10001",
    "requestMode": "mode34",
    "channelCode": "34",
    "agentBusinessName": "34",
    "agentNumber": "34",
    "agentInstitutionCode": "001",
    "agentAccountNumber": "098788"
}

输出json

{
    "BalanceEnquiryRequest": {

        "channel": null,
        "type": "mode34",
        "customerId": "098788",
        "customerIdType": null,
        "submissionTime": null,
        "reqTranId": "10001",
        "passcode": null
    }
}

【问题讨论】:

    标签: wso2 wso2esb orchestration


    【解决方案1】:

    首先您需要查看是否有单个元素或多个元素的要求。 如果它是单个元素,那么最好的选择是使用前面建议的有效负载中介。 如果您想要多个元素,请按照以下步骤操作。

    第 1 步:一旦请求进入您的序列,使用属性中介将其转换为 XML

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

    这会将传入的 json 转换为 XML。

    第 2 步:现在使用 XSLT Mediator 转换为所需的负载。

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
        <xsl:output omit-xml-declaration="yes" indent="yes"/>    
        <xsl:template match="/">          
            {
            "BalanceEnquiryRequest": {        
            <xsl:for-each select="//*[local-name()='root']">        
            "channel": null,
            "type": "<xsl:value-of select="requestMode"/>",
            "customerId": "<xsl:value-of select="agentAccountNumber"/>",
            "customerIdType": null,
            "submissionTime": null,
            "reqTranId": "<xsl:value-of select="requestID"/>",
            "passcode": null
            </xsl:for-each>
            }
            }        
        </xsl:template>
    </xsl:stylesheet>
    

    【讨论】:

      【解决方案2】:

      如果只是一个 BalanceEnquiryRequest,您可以使用 PayloadFactory mediator

      <payloadFactory media-type="json">
          <format>
              {
                  "BalanceEnquiryRequest": {
                      "channel": null,
                      "type": $1,
                      "customerId": $2,
                      ... etc
                  }
              }
          </format>
          <args> 
              <arg evaluator="json" expression="$.requestMode"/>
              <arg evaluator="json" expression="$.agentAccountNumber"/>
              ... etc
          </args>
      <payloadFactory>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2010-09-23
        • 2021-04-23
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多