开发者

Mapping value objects with Dozer

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) 开发者_如何学Cas @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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜