/** * Clone. * * @param orig * the orig * @return the serializable * @throws NotSerializableException * the not serializable exception */ static Serializable clone(final Serializable orig) throws NotSerializableException { byte[] bytes = Converter.serialize(orig); try { return Converter.deserialize(bytes); } catch (ClassNotFoundException canthappen) { throw new IllegalArgumentException("cannot clone " + orig, canthappen); } }
/** * Serialiazes and deserializes the given object. This can be used e.g. for * testing if you want to test the deserialized object if transient * attributes are initialized correct (transient attributes are null after * deserialization). * <p> * This method is a result of <a href= * "https://sourceforge.net/p/patterntesting/feature-requests/50/">feature * request 50</a>. * </p> * * @param object the object to serialize * @return the deserialized object * @throws NotSerializableException if serialization fails * @since 1.7.2 */ public static Serializable deserialize(final Serializable object) throws NotSerializableException { byte[] bytes = Converter.serialize(object); LOG.debug(object + " serialized in " + bytes.length + " bytes"); try { return Converter.deserialize(bytes); } catch (ClassNotFoundException canthappen) { throw new IllegalArgumentException("cannot be deserialized: " + object, canthappen); } }