Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have a problem with DataWeave 2 transformation. I have:

var parseDate = (dateStr) -> dateStr as DateTime {format: "yyyy-MM-dd"}

But when I am running this code I get:

Caused by: org.mule.runtime.api.el.ExpressionExecutionException: Cannot coerce String (2019-03-26) to DateTime, caused by: Text '2019-03-26' could not be parsed: Unable to obtain ZonedDateTime from TemporalAccessor: {},ISO resolved to 2019-03-26 of type java.time.format.Parsed

I am using DateTime cause it is detected as such when creating metadata. But the class itself has LocalDate bookingDate; - the problem is that when I am trying to use LocalDate - I get an error:

Unable to resolve reference of: `LocalDate`.

What can I do with this problem? Can I parse it somehow correctly? Or what can I do with the LocalDate problem mentioned above?

question from:https://stackoverflow.com/questions/66059895/dataweave-unable-to-obtain-zoneddatetime-from-temporalaccessor-when-parsing-a-s

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
1.1k views
Welcome To Ask or Share your Answers For Others

1 Answer

As your input string has only the date part, you can use the following DataWeave expression:

var parseDate = (dateStr) -> dateStr as Date {format: "yyyy-MM-dd"}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...