简体   繁体   中英

DataWeave 2 - transform Java ArrayList to XML with array item tags

I have a Java payload in Mule 4.3 which contains an ArrayList:

agentList = {ArrayList}
    0 = {SomeClass}
        id = "0"
        name = "Agent0"
    1 = {SomeClass}
        id = "1"
        name = "Agent1"

I want to transform this to XML as:

<agentList>
    <agent>
         <id>0</id>
         <name>Agent0</name>
    </agent>
    <agent>
         <id>1</id>
         <name>Agent1</name>
    </agent>
</agentList>

If I do a DataWeave transform output application/xml --- result: payload , I get this XML:

<result>
    <agentList>
         <id>0</id>
         <name>Agent0</name>
    </agentList>
    <agentList>
         <id>1</id>
         <name>Agent1</name>
    </agentList>
</result>

How can I transform the ArrayList so that I get each item enclosed by agent tags and the entire list as agentList ?

%dw 2.0
output application/xml
---
result: {
    agentList: payload.*agentList map (value) -> { agent: value }
}

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