简体   繁体   中英

Mule Dataweave Map with SplitBy

I have a Mule flow, which converts CSV data to XML. There is a field which I need to map and split by a character. I am receiving an error which states

Cannot coerce a :array to a :object.

Here is the results I need to achieve:

<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>

Here is the flow I am using:

    <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>

However my flow kicks back the following:

Cannot coerce a :array to a :object.

Here is what the raw data looks like that I am trying to map for the SerialSet field:

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

Should be a node for each item based on the key -> value pairs, in this instance it should look like:

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

In case anyone stumbles across this, here is the fix:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM