0

Hi am using model mapper 3.1.1. I want to skip the value assignment of destination property only if it is not null. But when I provide the condition is not getting added in the property condition.

@Configuration
public class ModelMapperInitializer {

    @Bean
    public ModelMapper modelMapper() {

        Condition<SourceObject, DestinationObject> isNotNull = context -> context.getDestination().getDestProperty() != null;
        
        ModelMapper modelMapper = new ModelMapper();
        
        modelMapper.typeMap(SourceObject.class, DestinationObject.class).addMappings(mapper -> 
             mapper.when(isNotNull).skip(SourceObject::getDestProperty, DestinationObject::setDestProperty));
        
        return modelMapper;
    }
}

Controller:

@Autowired
private ModelMapper modelMapper;
modelMapper.map(sourceObj, destObj);

Could anyone please help in fixing the issue.

Nathan
  • 13
  • 3

0 Answers0