将Java日期反序列化为Instant

I need to deserialize below two foramt into java.time.Instant in a singe code

2020-04-23T10:51:24.238+01:00 and 2019-11-11T15:44:10.201Z

我在第一种情况下出现belwow错误

nested exception is org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Cannot deserialize value of type java.time.Instant from String "2020-04-23T10:51:24.238+01:00": com.fasterxml.jackson.databind.exc.InvalidFormatException: Cannot deserialize value of type java.time.Instant from String "2020-04-23T10:51:24.238+01:00": Failed to deserialize java.time.Instant: (java.time.format.DateTimeParseException) Text '2020-04-23T10:51:24.238+01:00' could not be parsed at index 23

Is there any solution ? Also Is there any way to deserialize java.util.Date into java.time.Instant

评论
  • znon
    znon 回复
    有什么解决办法吗?也有什么方法可以将java.util.Date反序列化为java.time.Instant

    了解您的API:

    final java.util.Date date = new Date();
    final java.time.Instant instant = date.toInstant();