i have a mapper which uses resolve factory to turn a dto (with its id populated) to a domain entity. It all seems to work but in the generated mapper impl, it overwrites the resolved properties from whats in the dto.
mapper:
@Mapper(componentModel = "springlazy", unmappedTargetPolicy = ReportingPolicy.ERROR, unmappedSourcePolicy = ReportingPolicy.ERROR, uses = { TicketAccountResolver.class })
public interface TicketAccountMapper {
/**
* Converts TicketAccount domain class to DTO
*
* @param TicketAccountDto domain class
* @return TicketAccount DTO class. If null provided, would return null as well.
*/
TicketAccountDto map(TicketAccount domain);
/**
* Converts TicketAccount dto class to domain
*
* @param TicketAccountDto domain class
* @return TicketAccount DTO class. If null provided, would return null as well.
*/
TicketAccount map(TicketAccountDto dto);
}
resolver:
@Component
public class TicketAccountResolver {
@Autowired
TicketAccountRepository repository;
@ObjectFactory
public TicketAccount resolve(TicketAccountDto dto, @TargetType Class<TicketAccount> type) {
if (null != dto && dto.getId() != null) {
return repository.findById(dto.getId()).get();
}
// TODO not sure on best approach here, throw exception, return null, or do the below
return new TicketAccount(dto.getId());
}
generated mapper impl:
@Override
public TicketAccount map(TicketAccountDto dto) {
if ( dto == null ) {
return null;
}
TicketAccount ticketAccount = ticketAccountResolver.resolve( dto, TicketAccount.class );
ticketAccount.setDisplayName( dto.getDisplayName() );
ticketAccount.setId( dto.getId() );
ticketAccount.setName( dto.getName() );
return ticketAccount;
}
I need it to return the ticketAccount after resolve is called, not overwrite its fields with dto values.