Mockito-尝试模拟Objectmapper时出现LocalDate错误

时间:2018-10-29 11:09:33

标签: spring-boot mockito objectmapper

有一个字符串:

  private static final String JSON_APPLICANT_ORGANISATION2 =
            "{\"id\" : 1,\"establishmentDate\":{\"year\":2018,\"month\":\"OCTOBER\",\"monthValue\":10,\"dayOfMonth\":29,\"dayOfYear\":302,\"dayOfWeek\":\"MONDAY\",\"chronology\":{\"calendarType\":\"iso8601\",\"id\":\"ISO\"},\"era\":\"CE\",\"leapYear\":false}, // and it goes with lots of variables

必须在我要编写的单元测试的方法中将其转换为dto变量:

 ApplicantOrganisation applicantOrganisation =
                parseStringToObject(data.getApplicantOrganisation(), ApplicantOrganisation.class);

这是解析方法:

 public <T> T parseStringToObject(String data, Class<T> clazz) throws IOException {
        return objectMapper.readValue(data == null ? "{}" : data, clazz);
    }

但是mockito给出了错误:

Cannot construct instance of `java.time.LocalDate` (no Creators, like default construct, exist): cannot deserialize from Object value (no delegate- or property-based Creator)

我还应该使用委托吗?

0 个答案:

没有答案