ModelMapper: matches multiple source property hierarchies

modelmapper nested object mapping
modelmapper reflection
modelmapper constant
modelmapper mapping errors
unmapped destination properties found in typemap
java property map
mapper map in java
model mapper enum mapping

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 way than to write converter

org.modelmapper.ConfigurationException: ModelMapper configuration errors:

1) The destination property 
biz.models.CarWash.setSecondShift()/java.util.Date.setTime() matches 
multiple source property hierarchies:

biz.dto.CarWashDTO.getFirstShift()/java.time.LocalTime.getSecond()
biz.dto.CarWashDTO.getSecondShift()/java.time.LocalTime.getSecond()

The error was made by this code

@SpringBootTest
@RunWith(SpringRunner.class)
public class CarWashDTO2CarWash {

@Autowired
protected ModelMapper modelMapper;

@Test
public void testCarWashDTO2CarWash_allFiledShouldBeConverted(){
    CarWashDTO dto = CarWashDTO.builder()
            .name("SomeName")
            .address("SomeAddress")
            .boxCount(2)
            .firstShift(LocalTime.of(9, 0))
            .secondShift(LocalTime.of(20, 0))
            .phoneNumber("5700876")
            .build();

    modelMapper.addConverter((Converter<CarWashDTO, CarWash>) mappingContext -> {
        CarWashDTO source = mappingContext.getSource();
        CarWash destination = mappingContext.getDestination();
        destination.setId(source.getId());
        destination.setFirstShift(source.getFirstShift() == null ? null : Time.valueOf(source.getFirstShift()));
        destination.setSecondShift(source.getSecondShift() == null ? null : Time.valueOf(source.getSecondShift()));
        destination.setEnable(true);
        destination.setAddress(source.getAddress());
        destination.setBoxCount(source.getBoxCount());
        destination.setName(source.getName());
        destination.setDateOfCreation(source.getDateOfCreation());
        return destination;
    });

    final CarWash entity = modelMapper.map(dto, CarWash.class);
    assertNotNull(entity);
    assertEquals(2, entity.getBoxCount().intValue());
    assertEquals("SomeAddress", entity.getAddress());
    assertEquals("SomeName", entity.getName());
}

}

The modelmapper bean is built by the next configuration

@Bean
public ModelMapper modelMapper(){
    return new ModelMapper();
}

Dto:

public class CarWashDTO {
private Long id;
private String name;
private String address;
private String phoneNumber;
private Integer boxCount;
private LocalTime firstShift;
private LocalTime secondShift;
private LocalDateTime dateOfCreation;
}

Entity (firstShift and secondShift have java.sql.Time type):

public class CarWash {
private Long id;
private String name;
private String address;
private String phoneNumber;
private Integer boxCount;
private Time firstShift;
private Time secondShift;
private LocalDateTime dateOfCreation;
private Boolean enable;
private Owner owner;
}

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

matches multiple source property hierarchies problem · Issue #64 , Hi, I'm using JPA(with Hibernate) and wish to convert some composite domain to view layer, So I'm using ModelMapper also. At first, I defined  1) The destination property User. setPreference() / Preference. setUser() matches multiple source property hierarchies: Skipping to set user to Preference class suppress this error, but when saving data to persist returned exception that preference object instance couldn't get user property.

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

ModelMapper: matches multiple source property hierarchies, Matching strategy, Determines how source and destination tokens are ideal to use for source and destination object models with property hierarchies that are  Hello, I have chosen to use modelmapper because I have noticed that it handles in a better way generics super type (cf. Class MyClass) and inheritance of these types. I have nevertheless noticed a

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;
}

Configuration, joinMembers(mapping.getSourceProperties())); return addMessage( "The destination property %s matches multiple source property hierarchies:\n\n%s", Strings. So right now I have a model/dto that's giving me the " matches multiple source property hierarchies" exception. It's okay, I understand what it's complaining about. However, after adding the mappings for those properties, the exception continues to occur.

org.modelmapper.spi.PropertyMapping java code examples, C.setName() matches multiple source property hierarchies:" I'm pretty new to ModelMapper so apologies if I've missed something obvious! I am using ModelMapper with all default settings. destination property setId() matches multiple source property matches multiple source property hierarchies:

Map multiple attributes in deep hierarchy to a single object., return addMessage( "The destination property %s matches multiple source property hierarchies:\n\n%s" , Strings.joinMembers(mappings.get( 0 ). Hi, maybe i am doing something wrong, but i think it should be possiblie to resolve multiple source matches with a typemap. import org.junit.Test; import org.modelmapper.ModelMapper; public class ModelMapperTest { private final static Mo

org.modelmapper.ConfigurationException: ModelMapper , 3 years MappingException on CollectionConverter with 1.0.0 version; almost 3 years destination property setId() matches multiple source property hierarchies  The loose matching strategy is ideal to use for source and destination object models with property hierarchies that are very dissimilar. It may result in a higher level of ambiguous matches being detected, but for well-known object models it can be a quick alternative to defining mappings .

Comments
  • This configuration only makes ModelMapper skip the field. In this case the CarWashDTO.id field will be null after mapping.
  • This worked for me first I did 1) mapper.getConfiguration() .setAmbiguityIgnored(true); then configured the typeMap 2) mapper.createTypeMap(...).addMappings() after that set 3) mapper.getConfiguration() .setAmbiguityIgnored(false) and finally 4) mapper.validate()
  • This is the best answer. I have still seen conflicts with: modelMapper.getConfiguration().setAmbiguityIgnored(true);
  • modelMapper.getConfiguration().setAmbiguityIgnored(true) skips the value setter. But modelMapper.getConfiguration().setMatchingStrategy(MatchingStrategies.STRICT) sets the best matched value.This works for me.