开发者

Dozer mapping of generic lists

I have a ListWrapper like

public class ListWrapper<T> {

private List<T> entries = new ArrayList<T>();

public List<T> getEntries() {
    return entries;
}

public void setEntries(List<T> entries) {
    this.entries = entries;
}

and a bean like

public class AccountBo {
    private Stri开发者_Python百科ng accountName;

    public String getAccountName() {
        return accountName;
    }

    public void setAccountName(String accountName) {
        this.accountName = accountName;
    }

}

and another bean like

public class AccountDto {
    private String accountName;

    public String getAccountName() {
        return accountName;
    }

    public void setAccountName(String accountName) {
        this.accountName = accountName;
    }    
}

the idea now is to fill the list with beans of type AccountBo and use Dozer to map the list, then filled with AccountDto Beans.

    AccountBo accountA = new AccountBo();
    accountA.setAccountName("Person A");        
    AccountBo accountB = new AccountBo();
    accountB.setAccountName("Person B");

    ListWrapper<AccountBo> listWrapperBo = new ListWrapper();

    listWrapperBo.getEntries().add(accountA);
    listWrapperBo.getEntries().add(accountB);

    ListWrapper<AccountDto> dtoList = EntityMapper.getInstance().map(listWrapperBo, ListWrapper.class);

    List<AccountDto> listDto = dtoList.getEntries();

But - the Beans in the target list are of type AccountBo ....

What can I do to get a list of AccountDto's?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜