简体   繁体   中英

Query parameter date is changed to string in Mule

I have a query parameter called modifiedDate defined as date-only in the RAML file but when I look in the Mule debugger I see the modifiedDate 2001-10-10 as a string data type.

RAML

...
queryParameters:
   modifiedDate:
   type: date-only
   example: "2001-10-10
...

This is causing me a problem as when I call SQL Server stored procedure it is returning the error "Cannot convert NVARCHAR to Date".

I need to pass the modifiedDate to SQL Server in the format YYYY-MM-DD and as a Date datatype for this to work but I am also have problems converting it to a date datatype in Mule.

How can I change 2001-10-10 into a date datatype and keep the value the same?

I am using Anypoint Studio 6.2.2 and Mule 3.8.3.

Thanks

There are a couple of ways to parse a string as a date in mule

Dataweave:

%dw 1.0
%output application/java
---
{
    "modifiedDate" :  inboundProperties.'http.query.params'['modifiedDate'] as :date
}

will work without having to specify the date format

Groovy

payload['modDate'] = 
    Date.parse("yyyy-MM-dd", message.getInboundProperty('http.query.params')['modifiedDate']);
payload;

Both of these will convert the value into a java.util.Date

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM