I need to convert a dto to entity and the entity has a field to populate which doesn't needs any field of the dto. Indeed, the @Mapping annotation doesn't take any source.
Let's illustrate it with this simple example :
public class Employee {
private String firstName;
private String customId;
}
public class EmployeeDto {
private String firstName;
}
As you can the field customId of the Employee entity doesn't exist in the EmployeeDTO.
Also, I have the following formatter. Obviously, I created an @CustomIdGenerator @interface
public class EmployeeFormatter {
@CustomIdGenerator
public static String simulationIdGenerator() {
return // businessLogic
}
}
And finally my mapper looks like this :
@Mapper(uses = EmployeeFormatter.class)
public abstract class EmployeeMapper {
@Mapping(target = "customId", qualifiedBy = customIdGenerator.class)
public abstract Employee toEmployee(EmployeeDTO dto);
}
But in the generated classes it doesn't work. Do you know if there is any way to use a mapper whithout parameter ?
Thanks for your help ;)
EDIT :
Based on the response of @Nikolai Shevchenko the following code works :
@AfterMapping
void setCustomId(@MappingTarget Employee employee) {
employee.setCustomId(EmployeeFormatter.customIdGenerator());
}