ModelMapper skip a field

For the configuration to work need to add:
modelMapper.getConfiguration().setAmbiguityIgnored(true);

This is true only when the destination field matches to multiple source fields. Skipping the setting of a destination field will work without the above if there is either a 1-1 or a 0-1 match between source-destination.


Because of the generic parameters, we couldn't use the lambda expression.

ModelMapper modelMapper = new ModelMapper();
modelMapper.addMappings(new PropertyMap<Dto, Source>() {
                @Override
                protected void configure() {
                    skip(destination.getBlessedField());
                }
            });

For the configuration to work need to add:

modelMapper.getConfiguration().setAmbiguityIgnored(true);

E.g.

ModelMapper modelMapper = new ModelMapper();
modelMapper.getConfiguration().setAmbiguityIgnored(true);
modelMapper.addMappings(clientPropertyMap);
modelMapper.map(UserDTO, User);


PropertyMap<UserDTO, User> clientPropertyMap = new PropertyMap<UserDTO, User>() {
    @Override
    protected void configure() {
        skip(destination.getCity());
    }
};

Tags:

Modelmapper