The documentation say that api v2 returns dates formatted in “YYYY-MM-DDTHH:mm:ss.sssZ”.
This is also the case in most cases. However I have a customer on which the date is sometimes returend as “YYYY-MM-DDTHH:mm:ss.ssZ”, so using centiseconds instead of milliseconds.
Is this behavior somewhere documented? Is it known what causes the date be returned differently.
I have opened a ticket with them. Let’s see if and when they will answer. For now I’m using the following workaround:
@Slf4j
public class SafeDateDeserializer extends JsonDeserializer<Date> {
private static final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
private static final Date fallbackDate = new Date(0);
public SafeDateDeserializer() {
dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
}
@Override
public Date deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JsonProcessingException {
String date = p.getText();
try {
return dateFormat.parse(date);
} catch (ParseException e) {
log.error("Failed to parse date: " + date + ", falling back to beginning of time.");
return fallbackDate;
}
}
}