0
votes

I am building an application, where I have to hit a restful interface, and pass a specific section of the response to the UI.

The response model is quite huge with a lot of fields(String, array of objects, object,number datatypes), so using manual transformation is a big pain.

Is there a way to map the section of the response to a variable and directly send it to the UI.

I tried,

 %dw 2.0
%output application/xml

%var UserAcct= payload.UserResponse.UserDetailsResp.UserAccounts

---
{
  User: {
     "UserAccount": {   
        Account:  UserAcct
     }
   }
}

This doesn't work because, the payload has List, Array of Objects etc in the response and mapping to a variable throws an error. Is it possible to send the section payload.UserResponse.UserDetailsResp.UserAccounts directly in dataweave?? Please help.

1
Input payload and error text would be very helpful.jerney
Also your header says dw 2.0 but you are using dw 1.0 syntax. And as @jerney said some sample input and expected output, helps a lotmachaval

1 Answers

0
votes

It will be more helpful if you add Input payload, error and XML output.

Following is the code just by assuming your scenario. You can give this a try:

 %dw 2.0
 output application/xml
 ---
 {
   User: {
     "UserAccount": {   
        (payload.UserResponse.UserDetailsResp.UserAccounts map {
            Address:{
              <XMLFieldName>: $.<respectiveJSONFieldToMap>
              ....
            } 
        })
     }
   }
 }