Datetime coercion with DataWeave in Mulesoft

Haha Wa
May 13, 2021
Photo by Sigmund on Unsplash

I was extracting data from a json object and feeding it to another service but was running into this coercion error.

Cannot coerce String to DateTime

You may this similar error as well

Cannot coerce String (03/05/2021 12:43:00) to DateTime, caused by: Text ‘03/05/2021 12:43:00’ could not be parsed: Unable to obtain ZonedDateTime from TemporalAccessor: {},ISO resolved to 2021–05–03T12:43 of type java.time.format.Parsed

It seemed related to timezone so I tried a couple of ways adding a timezone but they didn’t work.

After checking Type Coercion with DataWeave I found out we should use `LocalDateTime` here and the error disappeared.

Thanks for reading to the end, there is a bonus site for you, have fun 😎

DataWeave Playground

--

--

Haha Wa

Web & Native app developer. Striving to change myself and the world for the better. I value active living, life-long learning, and keeping an open mind.