我正在尝试将一个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
}
}
发布于 2018-05-31 07:46:34
如果它只是一个单一的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>
发布于 2018-05-31 15:27:02
首先,您需要查看需求是否存在单个元素或多个元素。如果是单个元素,那么最好的选择是使用前面建议的有效负载中介器。如果您想要多个元素,请按照以下步骤操作。
步骤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>
https://stackoverflow.com/questions/50607980
复制相似问题