使用 lombok @Builder 时通过 Jackson 反序列化 '2021-09-24 00:00:00' 日期格式
Deserialize '2021-09-24 00:00:00' date format via Jackson when using lombok @Builder
我从响应中得到以下对象
{
"upload_date": "2021-09-24 00:00:00"
}
我正在使用 jackson 反序列化到 LocalDateTime 字段
@Getter
@Builder
@JsonDeserialize(builder = AdGroup.AdGroupBuilder.class)
public class AdGroup {
@JsonProperty("upload_date")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private LocalDateTime uploadDate;
}
但是我明白了 'Cannot deserialize value of type java.time.LocalDateTime from String "2021-09-24 00:00:00": Failed to deserialize java.time.LocalDateTime: (java.time.format.DateTimeParseException) Text '2021-09-24 00:00:00' could not be parsed at index 10'
我尝试使用“yyyy-MM-dd'T'HH:mm:ss”模式,with/without 'shape = JsonFormat.Shape.STRING' 但总是出现同样的错误。
你能试试吗-
@JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss'Z'")
和值示例 - “2021-12-08T16:49:02.449Z”
修复者:
@Getter
@Builder
@JsonDeserialize(builder = AdGroup.AdGroupBuilder.class)
public class AdGroup {
public static class AdGroupBuilder {
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private LocalDateTime uploadDate;
}
@JsonProperty("upload_date")
private LocalDateTime uploadDate;
}
我从响应中得到以下对象
{
"upload_date": "2021-09-24 00:00:00"
}
我正在使用 jackson 反序列化到 LocalDateTime 字段
@Getter
@Builder
@JsonDeserialize(builder = AdGroup.AdGroupBuilder.class)
public class AdGroup {
@JsonProperty("upload_date")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private LocalDateTime uploadDate;
}
但是我明白了 'Cannot deserialize value of type java.time.LocalDateTime from String "2021-09-24 00:00:00": Failed to deserialize java.time.LocalDateTime: (java.time.format.DateTimeParseException) Text '2021-09-24 00:00:00' could not be parsed at index 10'
我尝试使用“yyyy-MM-dd'T'HH:mm:ss”模式,with/without 'shape = JsonFormat.Shape.STRING' 但总是出现同样的错误。
你能试试吗-
@JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss'Z'")
和值示例 - “2021-12-08T16:49:02.449Z”
修复者:
@Getter
@Builder
@JsonDeserialize(builder = AdGroup.AdGroupBuilder.class)
public class AdGroup {
public static class AdGroupBuilder {
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private LocalDateTime uploadDate;
}
@JsonProperty("upload_date")
private LocalDateTime uploadDate;
}