December 25, 2019

Cannot coerce string to in MuleSoft DataWeave due to null

We cannot parse String to different data types when it is null or blank. We get Cannot coerce string to exception.

Use default keyword to fix this issue.

Sample code:

  1. output application/json  
  2. ---  
  3. payload map ( payload01 , indexOfPayload01 ) -> {  
  4.     Stree: payload01."Applicant Address Street",  
  5.     Birthdate: payload01."Applicant Birthdate" as Date default null,  
  6.     BorrowerId: payload01."Applicant Borrower Id" as Number default null,  
  7. }  

If "Applicant Birthdate" is blank or null, then null is set to Birthdate.
If "Applicant Borrower Id" is blank or null, then null is set to BorrowerId.

No comments:

Post a Comment