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

Categories

0 votes
1.3k views
in Technique[技术] by (71.8m points)

mule - DataWeave: Unable to obtain ZonedDateTime from TemporalAccessor when parsing a String to DateTime

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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"}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...