/** * A deep copy makes a distinct copy of each of the object's fields, recursing through the * entire graph of other objects referenced by the object being copied. Deep clone by serialize * and deserialize the object and return the deserialized version. A deep copy/clone, assuming * everything in the tree is serializable. * * NOTE: This method is very expensive!, don't use this method if you need performance. * * @param obj the object to clone, the object and object context must implement * java.io.Serializable. * @return the copied object include all object references. * @throws IllegalArgumentException Failed to perform deep clone. The object of the context * object is not implements java.io.Serializable. **/ public static Object deepClone(Object obj) { try { byte[] bArray = objectToByteBuffer(obj); return objectFromByteBuffer(bArray); } catch (Exception ex) { throw new IllegalArgumentException("Failed to perform deep clone on [" + obj + "] object. Check that the all object context are implements java.io.Serializable.", ex); } }