Java Mapping Utils – Orika vs Dozer

Java Mapping Utils – Orika vs Dozer

Java Mapping

Mapping between objects shouldn’t be anything new to you if you’re on this page. In enterprise development you often will have to map between DTOs, domain models, and data models. For the past 5 years or so I’ve been pretty content with dozer. I inject a DozerBeanMapper instance where I need it and map pretty easily between different objects. I mostly stick to convention over configuration, so I don’t have a bunch of xml or java code specifically setting up my java mappings, I just make sure to name properties the same so the mapper will figure this out for me.

My mapping problem

Like I said before, I’ve been happy with dozer. It’s not the most performant mapper but it works and it’s just what I’ve become comfortable with. Lately I’ve hit a big snag with Dozer during application startup. My DozerBeanMapper instance takes forever to initialize. Utils for java mapping should not take 20+ minutes to initialize at application startup. I even had instances where I would literally wait hours for DozerBeanMapper to initialize.

My initial reaction was to troubleshoot this issue to find the problem. I bumped up logging and dug in but I was thwarted by the weak returns from my google searches, so instead I went with a different approach.

In comes Orika

I went in search of a new java mapping utility and Orika is what I’ve settled on. I mainly settled on Orika because MapperFacade has some of the same method signatures I was using with Dozer. There was some refractoring to do, but it was as simple as switching out DozerMapper with MapperFacade, updating my maven to the new dependency, and removing the dozer dependency. I did it across about 2-3 projects in a day with no major or minor issues.

Performance – Orika vs Dozer

Now for the actual details you would probably come here to see. I found Orika with my usual method, typing into google what I’m currently using plus “vs”. Here’s a link for that google search. The most promising details I found were from Anatoliy Sokolenko.

Once I saw the article I was pretty much sold, but I had to test this myself first.

Like most people who grew up on the internet, I of course only skimmed the article at first. I quickly slapped together a test and to my surprise Dozer was faster. Then I went and actually read the whole article and saw Antoliy mentioned the performance increase occurs after many mappings. I changed my test and found that Orika got faster the more times it mapped objects. Antoliy found the increase in performance at 1,000,000 (1 million) iterations but I was seeing it as low as 1,000 (1 thousand) iterations.

You can test this yourself. You can use my code if you want to run a single junit test and get some output to system.out, or you can use Anatoliy’s code to test, which is much more robust and better thought out. They work similar, Anatoliy’s expects an input, mine you just change the iterations variable to do more or less mappings.

Conclusion

Not much of a conclusion to be had. Orika is faster and doesn’t cause me initialization problems. There are few instances where Dozer beats out Orika but I can’t imagine being faster at doing less is that much of a positive for Dozer. If you have a large project I can understand not wanting to change, but if you’re working on a small project or if you get to start a greenfield project I’d highly recommend going with Orika over Dozer.

Comments are closed.