MuleSoft · DataWeave

Cannot coerce String to Date

Short answer

This DataWeave error means a String could not be converted to a Date because the text is not a valid date for the format and parsing mode in use. Correct the input value, or pick a parsing mode that fits how strict you need to be.

VerifiedLast verified

01Error text

MuleSoft error
Cannot coerce String (02/31/2020) to Date, caused by: Text '02/31/2020' could not be parsed: Invalid date 'FEBRUARY 31'

02Likely causes

  • The text does not represent a real date. The docs' example is 02/31/2020, which fails with Invalid date 'FEBRUARY 31'.
  • The coercion uses the STRICT mode, which returns an error on an invalid date. The LENIENT and SMART modes autocorrect the date, each in a different way.

03How to fix it

  1. Read the message. It quotes the text that failed and the reason it could not be parsed.
  2. Check that the input value is a real date and that it matches the format used in the coercion.
  3. Decide whether invalid dates should fail. If they should, keep STRICT and correct or reject the bad input before the coercion.
  4. If an autocorrected date is acceptable, set another mode in the coercion, for example '02/31/2020' as Date {mode: "LENIENT", format: 'MM/dd/uuuu'}. In the docs' example LENIENT returns 03/02/2020 and SMART returns 02/29/2020.

iNotes

The values in the error text are the example from the DataWeave documentation. Your message quotes your own input.

04Official documentation

Test every fix in a non-production environment before you apply it to production. See how entries are verified.

More for MuleSoft work:Open MuleSoft jobsMuleSoft rates and salariesHire a senior MuleSoft developer

The iPaaS Brief

Subscribe to The iPaaS Brief.

The iPaaS newsletter for the people who run integrations. From iPaaS Group.

Free. You finish on theipaasbrief.com and confirm by email.