Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

BeanUtils.cloneBean() deep copy

Tags:

If all the objects within the bean implement Serializable interface, will BeanUtils.cloneBean() do a deep copy?

like image 297
hop Avatar asked Feb 13 '12 16:02

hop


People also ask

Does BeanUtils copyProperties do deep copy?

But BeanUtils. copyProperties does not perform a deep copy of fields and each level has to be created and separately copied.

Is it good to use BeanUtils copyProperties?

Copying properties of one object to another object is often tedious and error-prone for developers. BeanUtils class provides a copyProperties method that copies the properties of source object to target object where the property name is same in both objects.

How do you deep copy an ArrayList?

To create a true deep copy of ArrayList, we should create a new ArrayList and copy all the cloned elements to new ArrayList one by one and we should also clone Student object properly. To create deep copy of Student class, we can divide its class members to mutable and immutable types.

How do you deep copy an object?

Copy an Object With Object.assign() was the most popular way to deep copy an object. Object. assign() will copy everything into the new object, including any functions. Mutating the copied object also doesn't affect the original object.


2 Answers

Use SerializationUtils.clone method from the Apache Commons Lang for the deep copy. It copies the entire class hierarchy.

SerializationUtils.clone(object); 
like image 112
Vikas Chowdhury Avatar answered Sep 22 '22 15:09

Vikas Chowdhury


No, cloneBean() does shallow copy only. If you want deep copy. You may refer this link which has technique to do deep copy.

like image 26
kosa Avatar answered Sep 23 '22 15:09

kosa