MapStruct is mapping all the properties of source and destination by default if they have same name. The ignore
element in @Mapping
can be used for omitting any field mapping. But that's not I want. I want control over the mapping strategy. I want to specify something like:
@Mapper(STRATEGY=MAPPING_STRATEGY.SPECIFIED)
public interface EmployeeToEmployeeDTOMapper {
@Mappings({
@Mapping(target="id", source="id"),
@Mapping(target="name", source="name")
})
public EmployeeDTO employeeToEmployeeDTO (Employee emp);
}
Now this mapping is only meant to map id and name from source to destination. No other fields should be mapped unless specified in the mappings annotation.