I'm facing an error while deserialize the string to object.
org.opentest4j.MultipleFailuresError: Multiple Failures (2 failures) com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot construct instance of
java.time.LocalDate
(no Creators, like default construct, exist): no String-argument constructor/factory method to deserialize from String value ('2020-05-20') at [Source: (String)
JSON
{
"studentId":57,
"JoinedDate":"31-12-2019",
"DOB":"08-06-1998"
}
Model
public class Student{
private long studentId ;
private LocalDate JoinedDate;
private LocalDate DOB ;
public long getStudentId() {
return studentId;
}
public void setStudentId(long studentId) {
this.studentId = studentId;
}
public LocalDate getJoinedDate() {
return JoinedDate;
}
public void setJoinedDate(LocalDate joinedDate) {
JoinedDate = joinedDate;
}
public LocalDate getDOB() {
return DOB;
}
public void setDOB(LocalDate dOB) {
DOB = dOB;
}
Unit Test Class
@RunWith(SpringRunner.class)
@SpringBootTest(classes = Main.class)
@WebAppConfiguration
public class StudentTest{
private Student student;
private ObjectMapper jsonObjectMapper;
@Before
public void setUp() throws IOException {
jsonObjectMapper = new ObjectMapper();
jsonObjectMapper.setDateFormat(new SimpleDateFormat("dd-MM-yyyy"));
studentJson = IOUtils.toString(getClass().getResourceAsStream(CommonTestConstants.StudentPath+ "/Student.json"));
student = jsonObjectMapper.readValue(studentJson , Student.class);
}
Any one please advise
Reference Cannot construct instance of `java.time.ZonedDateTime` (no Creators, like default construct, exist)