逗号将字符串分隔为Map - Mulesoft

时间:2017-09-20 14:21:13

标签: java string csv dictionary mule

我有一个逗号分隔的字符串,看起来像这样

    CODE,TYPE,BATCHDATE
    SQ22,LOAD,20170505
    SF55,LPOO,20170908
    PL25,KLLQ,20170707

我想创建一个看起来像这样的有效负载映射

    CODE=SQ22,TYPE=LOAD,BATCHDATE=20170505
    CODE=SF55,TYPE=LPOO,BATCHDATE=20170908
    CODE=PL25,TYPE=KLLQ,BATCHDATE=20170707

这样做的最佳方法是什么?我已尝试在字符串和其他变压器之间使用变压器,但我总是遇到异常。Example of flow

    %dw 1.0
    $output application/csv
    ---
    payload

,第二个变压器是

    %dw 1.0
    $output application/java
    ---
    payload map ((payload,index) -> {
    batchCode: payload.CODE,
    batchType: payload.TYPE,
    batchDate: payload.BATCHDATE
    } as :object {
    class: "com.example.integration.Batch"
    })

我犯错的任何想法?

1 个答案:

答案 0 :(得分:0)

您的代码适用于这两种情况。请尝试将dataweave指令从$output application/java更改为%output application/java

更新: - 根据提到的错误,dataweave期待xml输入。请为CSV <dw:input-payload mimeType="application/csv"/>添加mime类型。代码看起来像

    <dw:transform-message doc:name="Transform Message">
        <dw:input-payload mimeType="application/csv"/>
        <dw:set-payload><![CDATA[%dw 1.0
            %output application/java
            ---
            payload]]>
        </dw:set-payload>
    </dw:transform-message>

希望这有帮助