close

[Solved] JSON parse error: Cannot deserialize value of type `java.time.LocalDateTime` from String

Hello Guys, How are you all? Hope You all Are Fine. Today I get the following error JSON parse error: Cannot deserialize value of type java.time.LocalDateTime from String in java. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How JSON parse error: Cannot deserialize value of type java.time.LocalDateTime from String Error Occurs?

Today I get the following error JSON parse error: Cannot deserialize value of type java.time.LocalDateTime from String in java.

How To Solve JSON parse error: Cannot deserialize value of type java.time.LocalDateTime from String Error ?

  1. How To Solve JSON parse error: Cannot deserialize value of type java.time.LocalDateTime from String Error ?

    To Solve JSON parse error: Cannot deserialize value of type java.time.LocalDateTime from String Error Update: If the millisecond part consists of 1, 2, 3 digits or is optional, you may use the following format:

  2. JSON parse error: Cannot deserialize value of type java.time.LocalDateTime from String

    To Solve JSON parse error: Cannot deserialize value of type java.time.LocalDateTime from String Error Update: If the millisecond part consists of 1, 2, 3 digits or is optional, you may use the following format:

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;

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.

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you? Thank You.

Also, Read

Leave a Comment