code: public static byte[] serialize(Object obj) throws IOException {
  
      ByteArrayOutputStream out = new ByteArrayOutputStream();
  
      ObjectOutputStream objOut = null;
  
      try {
        objOut = new ObjectOutputStream(out);
        objOut.writeObject(obj);
        objOut.flush();
  
        return out.toByteArray();
      }
      finally {
        close(objOut);
      }
    }
docs: Serializes the given {@link java.io.Serializable} object into an array fo bytes.
  
  @param obj the {@link java.io.Serializable} object to serialize into an array of bytes.
  @return the byte array of the serialized object.
  @throws IOException if an I/O error occurs during the serialization process.
  @see #deserialize(byte[])
  @see java.io.ByteArrayOutputStream
  @see java.io.ObjectOutputStream
  @see java.io.Serializable