【发布时间】:2021-09-12 14:03:39
【问题描述】:
Exception during serialization - message:
Cannot deserialize value of type `java.time.LocalDateTime` from String "2021-05-04T09:06:27-05:00":
Failed to deserialize java.time.LocalDateTime:
(java.time.format.DateTimeParseException) Text '2021-05-04T09:06:27-05:00'
@JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss", shape = JsonFormat.Shape.STRING )
@JsonProperty("inprogress_ts")
val inProgressTs: LocalDateTime
为什么这个@JsonFormat 模式不能解析String "2021-05-04T09:06:27-05:00"?
【问题讨论】:
-
我使用过@JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss", shape = JsonFormat.Shape.STRING ) 但这不起作用
-
这不是
String,您可以直接转换为LocalDateTime,因为它包含偏移量(-05:00)。使用OffsetDateTime,应该可以... -
谢谢,成功了