/** * Deep clone an {@code Object} using serialization. * <p>This is many times slower than writing clone methods by hand * on all objects in your object graph. However, for complex object * graphs, or for those that don't support deep cloning this can * be a simple alternative implementation. Of course all the objects * must be {@code Serializable}.</p> * * @param <T> the type of the object involved * @param object the {@code Serializable} object to clone * @return the cloned object */ @SuppressWarnings("unchecked") public static <T extends Serializable> T clone(final T object) { if (object == null) { return null; } final byte[] objectData = serialize(object); return (T) deserialize(objectData); }