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":
CodePudding user response:
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;