Search code examples
mappingdton-tier-architecturedozer

When to use mapping framework, when to map by hand?


I have a question about Parallel Object Hierarchies such as DTO.
Theses hierarchies has to be somehow mapped between each other. Most straightforward method is to use simple mapping by hand. In this case you simply write code which transfers property values one-by-one from one object to the other.
This method is very laborious, but it offers the most variability and the best performance. Also it's very easy to write such mapping.

Another method is to use some mapping framework such as DOZER. It should be less laborious this way but you loose some variability. Some complicated mappings are hard to achieve if not impossible. You also loose some performance.

So my question is:
Are there any recommendations when to use mapping framework and when to rather map by hand? Does it depend on complexity of your mapping? Or it's better to always use mapping framework?

Thanks in advance.


Solution

  • I'd say automate as much as possible, as long as it doesn't add complexity. If it's something complex and auto-mapping can't be easily achieved, then do it manually. Additionally, map by hand when you hit performance bottle necks. There isn't a solution that will always work for all scenarios. Make it work by automating as much as possible, when it breaks - fix it.