DTO and mapper generation from Domain Objects

Nicolas C picture Nicolas C · May 13, 2010 · Viewed 13.2k times · Source

I have plenty of java domain objects that I need to transform to DTOs.

Please, don't start with the anti-pattern thing, the Domain Objects are what they are because of a long history, and I can't modify them (or not too much, see below).

So, of course, we've passed the age of doing all that manually. I've looked around, and dozer seems the framework of choice for DTO mapping.

But... what I'd really like is this: annotate classes and fields that I want in DTO, and run a tool that would generate the DTOs and the mappers.

Does that sound too unreasonable?

Does such a tool already exist?

Answer

Jonathan picture Jonathan · Jun 24, 2011

Consider checking out ModelMapper.

It differs from Dozer and others in that it minimizes the amount of configuration needed by intelligently mapping object models. Where configuration is needed, ModelMapper offers a refactoring safe API that uses actual code to map properties and values rather than using string references or XML.

Check out the ModelMapper site for more info:

http://modelmapper.org