I have the following object from the response
{
"upload_date": "2021-09-24 00:00:00"
}
I am using jackson to deserialize into LocalDateTime field
@Getter
@Builder
@JsonDeserialize(builder = AdGroup.AdGroupBuilder.class)
public class AdGroup {
@JsonProperty("upload_date")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private LocalDateTime uploadDate;
}
But I get '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'
I tried to use "yyyy-MM-dd'T'HH:mm:ss" pattern, with/without 'shape = JsonFormat.Shape.STRING' but the same error always.
CodePudding user response:
Can you try -
@JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss'Z'")
And value exmaple - "2021-12-08T16:49:02.449Z"
CodePudding user response:
Gets fixed by:
@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;
}