java.lang.Object
org.seppiko.commons.utils.SerializationUtil
Serialization utility
JDK object serialization and deserialization
- Author:
- Leonard Woo
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> Tdeserialize(byte[] bytes, Class<T> clazz) Deserialization object.static <T> byte[]serialize(T object) Serialization object.
-
Method Details
-
serialize
Serialization object.- Type Parameters:
T- the object type. If object isnullreturn an empty bytes.- Parameters:
object- an object.- Returns:
- serialize byte array.
- Throws:
IOException- Any exception thrown by the underlyingOutputStream.SecurityException- if the stream header is incorrect.
-
deserialize
public static <T> T deserialize(byte[] bytes, Class<T> clazz) throws IOException, ClassNotFoundException, SecurityException Deserialization object.- Type Parameters:
T- the object type. If serialized object not found returnnull.- Parameters:
bytes- object byte array.clazz- the object type class.- Returns:
- the object.
- Throws:
IOException- Any exception thrown by the underlyingOutputStream. Or something is wrong with a class used by deserialization.ClassNotFoundException- Class of a serialized object cannot be found.SecurityException- if the stream header is incorrect.NullPointerException- if bytes isnullor clazz isnull.
-