0

I have a complex object hierarchy that has a couple of extends.

class One { String name; Color color; List clothes; }

class Two extends One { Test test; }

class Foo { One One; Two two; }

I want to copy all the attributes of a object of class One into a new object of class say another. How to do this ? Is there any library available ?

4 Answers 4

4

Here are a couple:

Dozer is pretty fast and has a good number of configuration options. Orika is supposedly very fast though I have not indecently confirmed that (check out the benchmarks they posted on their site).

Sign up to request clarification or add additional context in comments.

4 Comments

This is a nice try for an architecture I use to work with: when transforming TO to VO. It may be necessary anymore. Have you used it for something like that?
We use Dozer for copying entity objects to DTO's and it handles decouple objects and non-normative relationships well. The ability to define relationships in XML allows us to decouple the object representations from each other as well, which is great.
We are also in the middle of prototyping Orika as a replacement for Dozer, because it is supposed to be significantly faster. I can't give an expert opinion on it at the moment though.
Here is the result of benchmarks integrated into Jenkins Build bit.ly/Io3Jhw
3

Dozer is a Java Bean to Java Bean mapper that recursively copies data from one object to another.

You can define mappings for copying object fields programmatically, with annotations or XML.

Comments

2

Wel, I have used both orika and dozer, I can say orika is at least 10 times faster than dozer in my project after the replacement. And also orika requires less jvm heap memories. orika is faster is beacause it compile the mapping rules as a runtime java class to do the properties mapping instead of looking into the mapping rules in runtime and using java reflection to get and set the properties values in runtime.

Comments

1

There's another framework that is even faster than Orika, take a look there - http://inspire-software.com/confluence/display/GeDA/Benchmarks

My simple test with 4 fields in a class and 1000000 copy operations took 100ms for GeDA, 1000ms for Orika and 4000ms for Dozer

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.