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?
I think you could do this with a custom converter. See the section on custom converters in the dozer documentation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With