0

I have to make a web service call and send many attributes while calling. One of the attribute is birthDate which is of type java.util.Date. I want birthDate to have value of this form "1960-10-25T00:00:00".

@GetMapping("/someSearch")
public PolicySearchResponseResource searchSomething(@RequestParam String firstName,
  @RequestParam String lastName, @RequestParam Date birthDate) {

//call web service here and send birthDate in this form 1960-10-25T00:00:00...
}

When I send 1960-10-25T00:00:00 in request param, it is not recieving it and throwing error. Only this form "Oct 25 1960" is accepted. How to handle this?

Mohammed Shirhaan
  • 555
  • 1
  • 11
  • 27
  • 4
    Possible duplicate of [How to accept Date params in a GET request to Spring MVC Controller?](https://stackoverflow.com/questions/15164864/how-to-accept-date-params-in-a-get-request-to-spring-mvc-controller) – Sambit Aug 06 '19 at 14:24

1 Answers1

3

Try this:

@RequestParam(value="paramName") @DateTimeFormat(pattern="MMddyyyy") Date paramName

So in your case it will be:

@GetMapping("/someSearch")
public PolicySearchResponseResource searchSomething(@RequestParam String firstName,
  @RequestParam String lastName, @RequestParam(value="birthDate") @DateTimeFormat(pattern="yyyy-MM-dd'T'HH:mm:ss") Date birthDate) {

}