Take the 2-minute tour ×

I am having a Java bean, which i want to clone it to get a new instance, but in the new instance, I want few of the properties to have values, others i don't want to be cloned/copied.


Source:- Class ABC, Object src --> field1 = 10, field2 =5, field3 = 6, field4 = 20
Target:- Class ABC, Oject clone --> field1 = 10, field2 = 5, field3 = null, field4 = null

I can also use copyProperties but than, I have to create a similar but small class structure.

I can also use copyProperty but then, I have to write it multiple times.

Is there a good solution to this.

share|improve this question
Then you don't want a clone. –  Matt Ball Nov 9 '11 at 19:33
possible duplicate of Copy specific fields by using BeanUtils.copyProperties? –  Dave Newton Nov 9 '11 at 20:13
add comment

1 Answer

Use this method copyProperties(Object dest, Object orig) Copy property values from the origin bean to the destination bean for all cases where the property names are the same.

You have mentioned you are doing same.May you go to article.I always using for my spring web-app may be it also helpful to you.Comment if it solves your problem.


share|improve this answer
add comment

Your Answer


