Class SerializationUtil

java.lang.Object
org.seppiko.commons.utils.SerializationUtil

public class SerializationUtil extends Object
Serialization Utility

JDK object serialization and deserialization

Author:
Leonard Woo
See Also:
  • Method Details

    • serialize

      public static <T> byte[] serialize(T object) throws IOException, SecurityException
      Serialization object.
      Type Parameters:
      T - the object type. If object is null return an empty bytes.
      Parameters:
      object - an object.
      Returns:
      serialize byte array.
      Throws:
      IOException - Any exception thrown by the underlying OutputStream.
      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 return null.
      Parameters:
      bytes - object byte array.
      clazz - the object type class.
      Returns:
      the object.
      Throws:
      IOException - Any exception thrown by the underlying OutputStream. 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 is null or clazz is null.