具有SplitBy的Mule Dataweave映射

时间:2018-10-24 19:41:01

标签: mule esb dataweave

我有一个Mule流,它将CSV数据转换为XML。我需要映射一个字段并按字符进行拆分。我收到一条错误消息

Cannot coerce a :array to a :object.

这是我需要实现的结果:

<Dataset>
<ListingName> Name Here </ListingName>
<Description> Description Here </Description>
<Price>110,000</Price>
<SerialSet>
    <Hours>1255</Hours>
    <Serial>9110136</Serial>
</SerialSet>
<Dealer> Name Here </Dealer>
<DealerAddress>Continental, Ohio 45831</DealerAddress>
<Date>2018-10-24</Date>

这是我正在使用的流程:

    <dw:transform-message doc:name="Transform Message">
    <dw:input-payload mimeType="application/csv"/>
        <dw:set-payload><![CDATA[%dw 1.0
        %output application/xml
        ---
        {
        Tractor: {
           (payload map ((payload01 , indexOfPayload01) -> {
           Dataset: {
             ListingName: payload01.ListingName,
             Description: payload01.Description,
             Price: payload01.Price,
             SerialSet: (payload01.Serial replace /[{}]/ with "" splitBy ";")  map using (data = $ splitBy ":")   {
                (data[0]) : data[1]
             },
             Dealer: payload01.DealerName,
             DealerAddress: payload01.DealerAddress,
             Date: now as :string {format: "yyyy-MM-dd"}
             }
          }))
        }
        }
        ]]></dw:set-payload>

但是,我的流程反响如下:

Cannot coerce a :array to a :object.

这是我尝试映射到SerialSet字段的原始数据:

 <SerialSet>Hours: 3280; Serial Number: A7809001946; Condition: Used; Stock Number: 6465</SerialSet>

应该是基于键->值对的每个项目的节点,在这种情况下,它应类似于:

<SerialSet>
  <Hours>3280</Hours> 
  <Serial Number>A7809001946</Serial Number>
  <Condition>Used</Condition> 
  <Stock Number>6465</Stock Number>
</SerialSet>

1 个答案:

答案 0 :(得分:0)

万一有人偶然发现,这里是解决方法:

Serial: {
    ((payload01.Serial replace /[{}]/ with "" splitBy ";")  map using (data = $ splitBy ":")   {
                (data[0]) : data[1]
             })},