[“last_modified”])] with root cause
java.time.format.DateTimeParseException: Text ‘2018-06-06T13:19:53+00:00’ could not be parsed,unparsed text found at index 19
入站格式为2018-06-06T13:19:53 00:00
这是一种奇怪的格式.
我尝试了以下方法:
public class XYZ {
@DateTimeFormat(pattern = "yyyy-MM-ddTHH:mm:ss+00:00",iso = ISO.DATE_TIME)
private LocalDateTime lastModified;
}
最佳答案
没有什么可以阻止您创建自己的解串器.一个非常幼稚的示例如下:
原文链接:https://www.f2er.com/java/532959.htmlpublic class LocalDateTimeDeserializer extends JsonDeserializer<LocalDateTime> {
private static final String PATTERN = "yyyy-MM-dd'T'HH:mm:ss+00:00";
private final DateTimeFormatter formatter;
public LocalDateTimeDeserializer() {
this.formatter = DateTimeFormatter.ofPattern(PATTERN);
}
@Override
public LocalDateTime deserialize(JsonParser p,DeserializationContext ctxt) throws IOException {
return LocalDateTime.parse(p.getText(),formatter);
}
}
您需要注意的唯一一件事是,您需要通过在其周围添加单引号来转义“ T”.
使用解串器后,您可以像这样简单地注释字段:
@JsonDeserialize(using = LocalDateTimeDeserializer.class)
private LocalDateTime dateTime;