Modelmapper to convert from String to LocalDate

后端 未结 3 841
终归单人心
终归单人心 2021-01-12 00:08

My DTO is having date field in String format. My entity is having date as LocalDate. Currently I am skipping it from map and then later manually explicitly setting it (Strin

3条回答
  •  耶瑟儿~
    2021-01-12 00:23

    I am currently using ModelMapper 2.3.5 and the accepted solution does not work with me when I do ModelMapper.validate() for my mapping. See my related question.

    I managed to get also validation working - surprisingly - by removing provider totally so only converter is used. So like:

    modelmapper.addConverter(toStringDate);
    modelmapper.getTypeMap(String.class, LocalDate.class); // no provider, maps ok with me still
    modelmapper.validate();
    

提交回复
热议问题