我有一个流动的骡子流 - >选择 - > DATAMAPPER - >记录器
FILE端点处理包含40条记录的csv文件
DATAMAPPER将csv转换为JSON,并在预览中运行时以JSON格式显示所有40条记录
LOGGER将有效负载显示为字节而非JSON,当我将JSON转换为对象时,它以JSON格式显示有效负载,但只有1条记录。
我的疑问: 1.如何设置工作流来处理所有40条记录并将所有记录转换为JSON并从流中输出所有记录?
答案 0 :(得分:0)
你可以这样做。
<flow name="csv-to-jsonFlow">
<file:inbound-endpoint path="/src/main/resources/csv" connector-ref="File" responseTimeout="10000" doc:name="File">
<file:filename-regex-filter pattern=".*csv" caseSensitive="true"/>
</file:inbound-endpoint>
<dw:transform-message doc:name="Transform Message">
<dw:set-payload><![CDATA[%dw 1.0
%output application/json
---
payload]]></dw:set-payload>
</dw:transform-message>
<object-to-string-transformer doc:name="Object to String"/>
<logger message="#[payload]" level="INFO" doc:name="Logger"/>
</flow>
示例CSV文件:
name,age,gender
janos,29,male
juan,40,male
pedro,22,male
carla,34,female
jose,30,male
anne,25,female
rey,33,male
joyce,27,female
pia,20,female
ard,27,male
janos,29,male
juan,40,male
pedro,22,male
carla,34,female
jose,30,male
anne,25,female
rey,33,male
joyce,27,female
pia,20,female
ard,27,male
janos,29,male
juan,40,male
pedro,22,male
carla,34,female
jose,30,male
anne,25,female
rey,33,male
joyce,27,female
pia,20,female
ard,27,male
janos,29,male
juan,40,male
pedro,22,male
carla,34,female
jose,30,male
anne,25,female
rey,33,male
joyce,27,female
pia,20,female
ard,27,male
示例输出:
[
{
"name": "janos",
"age": "29",
"gender": "male"
},
{
"name": "juan",
"age": "40",
"gender": "male"
},
{
"name": "pedro",
"age": "22",
"gender": "male"
},
{
"name": "carla",
"age": "34",
"gender": "female"
},
{
"name": "jose",
"age": "30",
"gender": "male"
},
{
"name": "anne",
"age": "25",
"gender": "female"
},
{
"name": "rey",
"age": "33",
"gender": "male"
},
{
"name": "joyce",
"age": "27",
"gender": "female"
},
{
"name": "pia",
"age": "20",
"gender": "female"
},
{
"name": "ard",
"age": "27",
"gender": "male"
},
{
"name": "janos",
"age": "29",
"gender": "male"
},
{
"name": "juan",
"age": "40",
"gender": "male"
},
{
"name": "pedro",
"age": "22",
"gender": "male"
},
{
"name": "carla",
"age": "34",
"gender": "female"
},
{
"name": "jose",
"age": "30",
"gender": "male"
},
{
"name": "anne",
"age": "25",
"gender": "female"
},
{
"name": "rey",
"age": "33",
"gender": "male"
},
{
"name": "joyce",
"age": "27",
"gender": "female"
},
{
"name": "pia",
"age": "20",
"gender": "female"
},
{
"name": "ard",
"age": "27",
"gender": "male"
},
{
"name": "janos",
"age": "29",
"gender": "male"
},
{
"name": "juan",
"age": "40",
"gender": "male"
},
{
"name": "pedro",
"age": "22",
"gender": "male"
},
{
"name": "carla",
"age": "34",
"gender": "female"
},
{
"name": "jose",
"age": "30",
"gender": "male"
},
{
"name": "anne",
"age": "25",
"gender": "female"
},
{
"name": "rey",
"age": "33",
"gender": "male"
},
{
"name": "joyce",
"age": "27",
"gender": "female"
},
{
"name": "pia",
"age": "20",
"gender": "female"
},
{
"name": "ard",
"age": "27",
"gender": "male"
},
{
"name": "janos",
"age": "29",
"gender": "male"
},
{
"name": "juan",
"age": "40",
"gender": "male"
},
{
"name": "pedro",
"age": "22",
"gender": "male"
},
{
"name": "carla",
"age": "34",
"gender": "female"
},
{
"name": "jose",
"age": "30",
"gender": "male"
},
{
"name": "anne",
"age": "25",
"gender": "female"
},
{
"name": "rey",
"age": "33",
"gender": "male"
},
{
"name": "joyce",
"age": "27",
"gender": "female"
},
{
"name": "pia",
"age": "20",
"gender": "female"
},
{
"name": "ard",
"age": "27",
"gender": "male"
}
]
希望这有帮助。