We Are Going To Discuss About JSON parse error: Cannot deserialize value of type `java.time.LocalDateTime` from String. So lets Start this Java Article.
JSON parse error: Cannot deserialize value of type `java.time.LocalDateTime` from String
- JSON parse error: Cannot deserialize value of type `java.time.LocalDateTime` from String
There are milliseconds in the input string, so your format should be “yyyy-MM-dd'T'HH:mm:ss.SSS”
Update:
If the millisecond part consists of 1, 2, 3 digits or is optional, you may use the following format:@JsonFormat(shape=JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss[.SSS][.SS][.S]") private LocalDateTime updatedTime;
- Cannot deserialize value of type `java.time.LocalDateTime` from String
There are milliseconds in the input string, so your format should be “yyyy-MM-dd'T'HH:mm:ss.SSS”
Update:
If the millisecond part consists of 1, 2, 3 digits or is optional, you may use the following format:@JsonFormat(shape=JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss[.SSS][.SS][.S]") private LocalDateTime updatedTime;
Solution 1
There are milliseconds in the input string, so your format should be “yyyy-MM-dd’T’HH:mm:ss.SSS”
Update:
If the millisecond part consists of 1, 2, 3 digits or is optional, you may use the following format:
@JsonFormat(shape=JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss[.SSS][.SS][.S]")
private LocalDateTime updatedTime;
Original Author Of This Content
Solution 2
You can remove the annotation @JsonFormat and let it works in a default way. It is working fine for me even if I removed the millisecond.
@NotNull
@FutureOrPresent(message = ErrorMessages.INVALID_CAMPAIGN_START_DATE)
//@JsonFormat(pattern = "MM/dd/yyyy")
private LocalDateTime campaignStartDate;
JSON Request:
{ "campaignStartDate" : "2020-12-31T15:53:16",
"campaignExpDate" : "2021-01-24T15:53:16",
}
{
"campaignStartDate" : "2020-12-31T15:53:16.45",
"campaignExpDate" : "2021-01-24T15:53:16.45",
}
{
"campaignStartDate" : "2020-12-31T15:53:16.445",
"campaignExpDate" : "2021-01-24T15:53:16.445",
}
These JSON requests will work fine.
Original Author Of This Content
Solution 3
I had the same error, I used this one with “pickupDate”:”2014-01-01T00:00:00″
@JsonDeserialize(using = LocalDateTimeDeserializer.class)
@JsonSerialize(using = LocalDateTimeSerializer.class)
private LocalDateTime pickupDate;
Original Author Of This Content
Conclusion
So This is all About This Tutorial. Hope This Tutorial Helped You. Thank You.