How to use Dozer to copy data between classes without destroying the target class

114 views Asked by At

Using the example bellow:

public void reload(WorkTemplateDTO workTarget) throws Exception  {
    WorkTemplateDTO work = this.load(data.getId());
    workTarget= mapper.map(work, WorkTemplateDTO.class);
}

The instance 'workTarget' received as argument and destination of the copy is being replaced by a new instance with data from 'work'.

I would like to know if is possible to use Dozer to just copy data from source (work) to destination (workTarget) without destroing the old instance of 'workTarget'.

Tks!

1

There are 1 answers

0
Ravi On BEST ANSWER

Dozer also allows object to object mapping, so you can use the mapper in following way

public void reload(WorkTemplateDTO workTarget) throws Exception  {
    WorkTemplateDTO work = this.load(data.getId());
    mapper.map(work, workTarget);
}

ref: DozerBeanMapper