5

I'm using Dozer to map my DTOs to JPA entities.

One of the use-cases is that a DTO representation of an already existing entity arrives on a WS, then I find the entity using JPA and use Dozer to map the DTO on the found entity using map(source, destination) way of mapping (not the map(source, destinationClass)).

I have some value objects (with the classic immutable value object semantics) on my entities (such as Address) as @Embeddables. The thing is, that I want dozer to always create a new Address instance when setting it on e.g.: Employee object, and not map on the already existing Address instance.

So with the following classes:

public class Employee {

    private Address address;

    public void setAddress(Address address) {
        this.address = address;
    }

    public Address getAddress() {
        return this.address;
    }

}

I want dozer to call setAddress() always with a new Address instance and not by trying to map the new Address' fields with getAddress().

Is there any way to do this?

nihilist84
  • 1,191
  • 3
  • 11
  • 20

1 Answers1

3

I think you could do this with a custom converter. See the section on custom converters in the dozer documentation.

mark-cs
  • 4,677
  • 24
  • 32