Ad

Failed To Convert Value Of Type 'java.lang.String' To Required Type 'java.util.Date' When Sending GET Request

I have this method in my Controller (This is a Kotlin method, but I think you can understand it):

open fun getAis(
        @RequestParam("beginPeriodDate") @DateTimeFormat(pattern = "yyyy-MM-dd") beginPeriodDate: Date,
        @RequestParam("request") request: Boolean,
        @RequestParam("requestNumber") requestNumber: String,
        @RequestParam("sender") sender: String
): Data =
        service.get(beginPeriodDate, request, requestNumber, sender)

And I am trying to reach it via browser. I'm sending this: http://localhost:8097/shep/sync/ais?beginPeriodDate=2019-08-25?request=false?requestNumber=272710100307142417?sender=2727851024302531

And getting this:

Failed to convert value of type 'java.lang.String' to required type 
'java.util.Date'; nested exception is 
 org.springframework.core.convert.ConversionFailedException: Failed to 
 convert from type [java.lang.String] to type 
[@org.springframework.web.bind.annotation.RequestParam 
@org.springframework.format.annotation.DateTimeFormat java.util.Date] for 
value '2019-08-25?request=false?requestNumber='2710100307142417'? 
sender='27851024302531''; nested exception is 
 java.lang.IllegalArgumentException: Invalid format: "2019-08-25? 
request=false?requestNumber='27..." is malformed at "?request=false? 
requestNumber='27..."
Ad

Answer

Seems like your request URI is malformed & delimits parameters, not ?. in other words what you need is

?beginPeriodDate=2019-08-25&request=false&requestNumber='2710100307142417'&sender='27851024302531' 

also, if there's no particular reason to do it, i would drop the single quotes around requestNumber and sender values, which would make it look like this

?beginPeriodDate=2019-08-25&request=false&requestNumber=2710100307142417&sender=27851024302531
Ad
source: stackoverflow.com
Ad