public static byte[] serializeObject(final Object obj) throws IOException {
    final ByteArrayOutputStream out = new ByteArrayOutputStream();

    ObjectOutputStream objOut = null;

    try {
      objOut = new ObjectOutputStream(out);
      objOut.writeObject(obj);
      objOut.flush();

      return out.toByteArray();
    } finally {
      close(objOut);
    }
  }
Convenience method to serialize a Serializable Object into a byte array.
<p>

@param obj the Serializable Object to serialize into an array of bytes.
@return a byte array of the serialized Object.
@throws IOException if an I/O error occurs during the serialization process.
@see #deserializeObject(byte[])
@see java.io.ByteArrayOutputStream
@see java.io.ObjectOutputStream
@see java.io.Serializable
geode-core/src/main/java/org/apache/geode/internal/util/IOUtils.java