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> T
deserialize
(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 isnull
return 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 isnull
or clazz isnull
.
-