Using Spring @RestController to handle HTTP GET with ZonedDateTime parameters

I am creating an endpoint that will receive dates for server-side filtering. The code is as follows:

@RequestMapping(
        value = "/test",
        method = RequestMethod.GET,
        produces = {MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE}
)
@ResponseStatus(HttpStatus.OK)
public TestSummaryModel getTestSummaryByDate(
        @RequestParam ZonedDateTime start,
        @RequestParam ZonedDateTime end) {

    return testService.getTestBetween(start, end);

}

When I try to call my endpoint, I get an HTTP 400 error. "The request sent by the client was syntactically incorrect."

I tried different date formats, but none of them worked. Am I missing something? I read about @DateTimeFormat, but although I added it, it didn't work.

@RequestParam @DateTimeFormat(pattern = "dd-MM-yyyy") ZonedDateTime start

This is an example of the query I am making:

http: // host / test-api / v1 / test-summary / test? start = 09-09-2015 & end = 09-09-2015

Thanks!

+4
source share
1 answer

@DateTimeFormat - , . Spring MVC 4 ZonedDateTime.

.

, dd-MM-yyyy, ZonedDateTime.

Try

@RequestParam("start") @DateTimeFormat(iso = ISO.DATE_TIME) ZonedDateTime start

...?start=2014-04-23T04:30:45.123Z

, , @DateTimeFormat.

+5

Source: https://habr.com/ru/post/1606881/


All Articles