close

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

Today We are Going To Solve JSON parse error: Cannot deserialize value of type `java.time.LocalDateTime` from String in Java. Here we will Discuss All Possible Solutions and How this error Occurs So let’s get started with this Article.

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

  1. How to Fix JSON parse error: Cannot deserialize value of type `java.time.LocalDateTime` from String Error?

    To Fix JSON parse error: Cannot deserialize value of type `java.time.LocalDateTime` from String Error just Use the “yyyy-MM-dd'T'HH:mm:ss.SSS” format. You should use the “yyyy-MM-dd'T'HH:mm:ss.SSS” format to solve this error. So just use it like below
    @JsonFormat(shape=JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss[.SSS][.SS][.S]") private LocalDateTime updatedTime;

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

    To Fix JSON parse error: Cannot deserialize value of type `java.time.LocalDateTime` from String Error just Use the below code. You can use the below one code to solve this error @JsonDeserialize(using = LocalDateTimeDeserializer.class) @JsonSerialize(using = LocalDateTimeSerializer.class) private LocalDateTime pickupDate;

Solution 1 : Use the “yyyy-MM-dd’T’HH:mm:ss.SSS” format

You should use the “yyyy-MM-dd’T’HH:mm:ss.SSS” format to solve this error. So just use it like below

@JsonFormat(shape=JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss[.SSS][.SS][.S]")
private LocalDateTime updatedTime;

Solution 2 : Use the below code

You can use the below one code to solve this error

@JsonDeserialize(using = LocalDateTimeDeserializer.class)
@JsonSerialize(using = LocalDateTimeSerializer.class)
private LocalDateTime pickupDate;

Conclusion

So these were all possible solutions to this error. I hope your error has been solved by this article. In the comments, tell us which solution worked? If you liked our article, please share it on your social media and comment on your suggestions. Thank you.

Also Read These Solutions

Leave a Comment