ModelMapper: matches multiple source property hierarchies

后端 未结 4 938
孤城傲影
孤城傲影 2021-02-18 16:06

I cannot resolve modelMapper error. Do you have any ideas where is the issue?

NB: In view java.sql.Time doesn\'t have non-argument constructor I didn\'t find the better

相关标签:
4条回答
  • 2021-02-18 16:30

    I am not sure how it was with ModelMapper when question was asked but using converter should be straightforward. Instead of implementing a converter for the whole class implement it to the types that actually need conversion. So like:

    public static Converter<LocalTime, Time> timeConverter = new AbstractConverter<>() {
        @Override
        protected Time convert(LocalTime source) {
            return null == source ? null : Time.valueOf(source);
        }
    }; 
    

    Then it is just to:

    mm.addConverter(timeConverter);
    

    Guess if using Spring or EJB you know howto add this into your configuration.

    0 讨论(0)
  • 2021-02-18 16:36

    This resolved my problem: modelMapper.getConfiguration().setAmbiguityIgnored(true);

    0 讨论(0)
  • 2021-02-18 16:41

    try modelMapper.getConfiguration().setMatchingStrategy(MatchingStrategies.STRICT)

    0 讨论(0)
  • 2021-02-18 16:48

    You need to customize ModelMapper configuration during Bean initialization with the help of a PropertyMap: http://modelmapper.org/user-manual/property-mapping/

    @Bean
    public ModelMapper modelMapper(){
        ModelMapper mm = new ModelMapper();
    
        PropertyMap<CarWashDTO, CarWash> propertyMap = new PropertyMap<CarWashDTO, CarWash> (){
            protected void configure() {
                map(source.getId()).setId(null);
            }
        }
    
        mm.addMappings(propertyMap);
        return mm;
    }
    
    0 讨论(0)
提交回复
热议问题