在 WSO2 Config Lang 中将一种数据类型对象转换为另一种数据类型对象
Converting One Data Type Object to another Data Type Object in WSO2 Config Lang
我正在尝试将一个 json 有效载荷转换为另一个,我尝试使用 DataMapper
但输出有效载荷与输入有效载荷不匹配,因此我无法映射这两个数据。
我尝试使用 enrich mediator,但我似乎无法找到解决办法。
输入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
}
}
如果它只是一个 BalanceEnquiryRequest,您可以使用 PayloadFactory mediator.
<payloadFactory media-type="json">
<format>
{
"BalanceEnquiryRequest": {
"channel": null,
"type": ,
"customerId": ,
... etc
}
}
</format>
<args>
<arg evaluator="json" expression="$.requestMode"/>
<arg evaluator="json" expression="$.agentAccountNumber"/>
... etc
</args>
<payloadFactory>
首先要看需求是单元素还是多元素。
如果它是单个元素,那么最好的选择是按照之前的建议使用有效载荷中介。
如果您想要多个元素,请按照以下步骤操作。
第 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 调解器将其转换为所需的负载。
<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>
我正在尝试将一个 json 有效载荷转换为另一个,我尝试使用 DataMapper
但输出有效载荷与输入有效载荷不匹配,因此我无法映射这两个数据。
我尝试使用 enrich mediator,但我似乎无法找到解决办法。
输入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
}
}
如果它只是一个 BalanceEnquiryRequest,您可以使用 PayloadFactory mediator.
<payloadFactory media-type="json">
<format>
{
"BalanceEnquiryRequest": {
"channel": null,
"type": ,
"customerId": ,
... etc
}
}
</format>
<args>
<arg evaluator="json" expression="$.requestMode"/>
<arg evaluator="json" expression="$.agentAccountNumber"/>
... etc
</args>
<payloadFactory>
首先要看需求是单元素还是多元素。 如果它是单个元素,那么最好的选择是按照之前的建议使用有效载荷中介。 如果您想要多个元素,请按照以下步骤操作。
第 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 调解器将其转换为所需的负载。
<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>