Our Rest API is used by several external parties. They all use "ISO-ish" formats, but the formatting of the time zone offset is slightly different. These are some of the most common formats we see:
2018-01-01T15:56:31.410Z
2018-01-01T15:56:31.41Z
2018-01-01T15:56:31Z
2018-01-01T15:56:31+00:00
2018-01-01T15:56:31+0000
2018-01-01T15:56:31+00
In my controller I use the following annotations:
@RequestMapping(value = ["/some/api/call"], method = [GET])
fun someApiCall(
@RequestParam("from")
@DateTimeFormat(iso = ISO.DATE_TIME)
from: OffsetDateTime
) {
...
}
It parses variant 1-4 just fine but produces a 400 Bad Request error for variants 5 and 6 with the following exception:
Caused by: java.time.format.DateTimeParseException: Text '2018-01-01T13:37:00.001+00' could not be parsed, unparsed text found at index 23
at java.time.format.DateTimeFormatter.parseResolved0(DateTimeFormatter.java:1952)
at java.time.format.DateTimeFormatter.parse(DateTimeFormatter.java:1851)
How can I make it accept all the above ISO formatting variants (even if they are not 100% compliant to the ISO standard)?