I am trying to create an application using springboot-java, front end as html/css/javascript. I get the below error while doing a post to create an employee record. I am passing a join date which is causing the error.
failed - {"readyState":4, "responseText":"{\"timestamp\":1515066928232, \"status\":500, \"error\":\"Internal Server Error\", \"exception\":\"java.time.format.DateTimeParseException\", \"message\":\"Text '01-17-2018' could not be parsed at index 0\", \"path\":\"/employee/\"}", "responseJSON":{"timestamp":1515066928232, "status":500, "error":"Internal Server Error", "exception":"java.time.format.DateTimeParseException", "message":"Text '01-17-2018' could not be parsed at index 0", "path":"/employee/"}, "status":500, "statusText":"error"}
Below is the code I use in java:
private static final long serialVersionUID = -7314008048174880868L;
private static final DateTimeFormatter DATE_FORMAT = DateTimeFormatter.ofPattern("MM-dd-yyyy");
private Integer organisation;
private String empName;
private String joinDate;
private String gender;
private String designation;
private String email;
public EmployeeDto(){
}
public EmployeeDto(Integer organisation, String empName, String joinDate, String gender,
String designation, String email) {
super();
this.organisation = organisation;
this.empName = empName;
this.joinDate = joinDate;
this.gender = gender;
this.designation = designation;
this.email = email;
}
public Employee buildEmployee(){
return new Employee(this.empName,LocalDate.parse(this.joinDate),this.gender,this.designation,this.email);
}
I use the below date converter:
@Converter(autoApply = true)
public class LocalDateAttributeConverter implements AttributeConverter<LocalDate, Date> {
@Override
public Date convertToDatabaseColumn(LocalDate locDate) {
return (locDate == null ? null : Date.valueOf(locDate));
}
@Override
public LocalDate convertToEntityAttribute(Date sqlDate) {
return (sqlDate == null ? null : sqlDate.toLocalDate());
}
}
I am unable to find the root cause....