【发布时间】:2023-03-30 21:04:01
【问题描述】:
我正在尝试使用 json-to-xml-transformer 将 json 消息转换为 xml,但无法找到有关其使用的文档。我不需要对数据进行任何转换,只需将 json 属性转换为 xml 标签即可。当我尝试使用转换器时,我得到的只是 json 中的第一个元素。
输入 JSON:
{
"site":"mysite",
"erpCustno":"123",
"shipToState":"PA",
"shipToZip":"16684",
"lineInfo": [
{
"lineNumber": "10",
"product": "MAT203"
}
]
}
XML 输出:
<?xml version='1.0'?><site>mysite</site>
流程:
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:json="http://www.mulesoft.org/schema/mule/json" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:spring="http://www.springframework.org/schema/beans" version="EE-3.5.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/json http://www.mulesoft.org/schema/mule/json/current/mule-json.xsd">
<flow name="newpigrestFlow1" doc:name="newpigrestFlow1">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8087" doc:name="HTTP"/>
<json:json-to-xml-transformer mimeType="text/xml" doc:name="JSON to XML" ignoreBadInput="true"/>
</flow>
</mule>
转换器是否需要一个映射类,或者它可以直接将 JSON 转换为 XML(反之亦然,使用 xml-to-json-transformer)?
我正在使用 Anypoint Studio 2014 年 7 月并部署到 Mule EE 3.5.0。
【问题讨论】:
标签: json mule mule-studio