/** * Gets the size of the given object - this is the number of bytes the given * object needs for serialization. * * @param object * the object * @return the size of * @since 1.5 (14.10.2014) */ public static int getSizeOf(final Serializable object) { try { return Converter.serialize(object).length; } catch (NotSerializableException ex) { throw new IllegalArgumentException("not serializable: " + object, ex); } }
/** * 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); } }