Using version 1.1.0.Beta1
So I'm trying to map a couple of objects with bidirectional dependencies (and thus we have a graph instead of a tree). The naive implementation causes a stack overflow since the mappers just constantly bounce back and forth between the objects, and I'm not seeing anything in the documentation that seems to cover this or offer a solution.
public class AccountEntity {
private Set<ContractEntity> contracts;
}
public class ContractEntity {
private AccountEntity account;
}
public class Account {
private Set<Contract> contracts;
}
public class Contract {
private Account account;
}
@Mapper(uses = ContractMapper.class)
public interface AccountMapper {
Account toAccount(AccountEntity accountEntity);
AccountEntity toAccountEntity(Account account);
Set<Account> toAccounts(Collection<AccountEntity> accountEntities);
Set<AccountEntity> toAccountEntities(Collection<Account> accounts);
}
@Mapper(uses = AccountMapper.class)
public interface ContractMapper {
Contract toContract(ContractEntity contractEntity);
ContractEntity toContractEntity(Contract contract);
Set<Contract> toContracts(Collection<ContractEntity> contractEntities);
Set<ContractEntity> toContractEntities(Collection<Contract> contracts);
}
Ideally the dependency would be kept after the mapping (the contract.account object instance is the same object instance whose account.contracts holds that contract) however I would take a solution that prevents the stack overflow.