Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot deserialize value of type java.time.LocalDate from String

I have input json payload like below. My Entity Class ImportTrans eventTime type currently is LocalDate . How i can format it to accept the json input format.

{
"eventId":"ep9_0579af51-4b5c",
"eventTime":"5/11/2022 5:50:58 PM",
"eventType":"Update"
}

public class ImportTrans implements Serializable {
@Id
private Long processId;// AutoGenerator
private String eventId;
private LocalDate eventTime;
private String eventType;
}

HttpMessageNotReadableException Bad request 400 error - JSON parse error: Cannot deserialize value of type java.time.LocalDate from String "5/11/2022 5:50:58 PM":

like image 375
VKP Avatar asked Oct 17 '25 00:10

VKP


1 Answers

Based on your spring-boot version, if its >=2.2 , then below might work straight-away

import com.fasterxml.jackson.annotation.JsonFormat;
..

@JsonFormat(pattern = "dd/MM/yyyy HH:mm:ss")
private LocalDate eventTime;
like image 133
Ashish Patil Avatar answered Oct 18 '25 17:10

Ashish Patil



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!