Consider the following POJOs:
public class PersonVo {
private String firstName;
private String lastName;
}
private class PersonEntity {
private String fullName;
}
Using MapStruct, I want create mapper that PersonVo to PersonEntity.
I need mapping multiple source fields firstName, lastName to one target filed fullName.
Here is pseudo code what I want to.
[Want Solution A]
@Mapper
public interface PersonMapper {
@Mapping(target = "fullName", source = {"firstName", "lastName"}, qualifiedByName="toFullName")
PersonEntity toEntity(PersonVo person);
@Named("toFullName")
String translateToFullName(String firstName, String lastName) {
return firstName + lastName;
}
}
[Want Solution B]
@Mapper
public interface PersonMapper {
@Mapping(target = "fullName", source = PersonVo.class, qualifiedByName="toFullName")
PersonEntity toEntity(PersonVo person);
@Named("toFullName")
String translateToFullName(PersonVo pserson) {
return pserson.getFirstName() + pserson.getLastName();
}
}
Is there any way this can be achieved?