I have a @GetMapping
mapped controller method with 3 Request Parameters: id
, startDate
, and endDate
.
I want it to accept timestamps for both date parameters, but only get it working using ISO formatted strings.
My Method looks like below:
@GetMapping("/getNumberOfHolidays")
public ResponseEntity<Properties> getNumberOfHolidays(@RequestParam Integer locationId,
@RequestParam("startDate") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) Date startDate,
@RequestParam("endDate") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) Date endDate){
Integer noOfDays = 0;
Properties prop = new Properties();
try {
noOfDays = service.getNumberOfHolidays(locationId, startDate, endDate);
prop.setProperty("Number of Holidays", noOfDays.toString());
} catch(Exception e) {
//return
}
//return
}
When I invoke this method with startDate = 2020-08-01
and endDate = 2020-08-10
(both in YYYY-mm-DD
), it's working as expected and properly converts the strings from the url.
Example:
http://localhost:8080/TrackContract/getNumberOfHolidays?locationId=2&startDate=2020-08-01&endDate=2020-08-10
But when I call the method with timestamps like startDate = 1596220200000
and endDate = 1596997800000
it's not working(giving 400 Bad Request in postman)
Example:
http://localhost:8080/TrackContract/getNumberOfHolidays?locationId=2&startDate=1596220200000&endDate=1596997800000
I tried to set the timestamp value to request param like below:
@RequestParam("startDate") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDateTime startDate,
@RequestParam("endDate") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDateTime endDate
But that didn't work. Can someone help me here how can I set timestamp value to the RequestParam startDate and endDate?