public static <T extends Serializable> byte[] serialize(T ser)
    throws IOException
  {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ObjectOutputStream oos = new ObjectOutputStream(baos);
    try
    {
      oos.writeObject(ser);
    }
    finally
    {
      oos.close();
    }
    return baos.toByteArray();
  }
public static <T extends Serializable> byte[] serialize(T ser)
    throws IOException
  {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ObjectOutputStream oos = new ObjectOutputStream(baos);
    try
    {
      oos.writeObject(ser);
    }
    finally
    {
      oos.close();
    }
    return baos.toByteArray();
  }
public static < T extends Serializable > byte [ ] serialize ( T ser ) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream ( ) ; ObjectOutputStream oos = new ObjectOutputStream ( baos ) ; try { oos . writeObject ( ser ) ; } finally { oos . close ( ) ; } return baos . toByteArray ( ) ; }
Turns the object into a <code>byte[]</code> by serializing it in memory.

@param ser the serializable object
@exception IOException if there is a problem in the serialization step
Turns the object into a <code > byte [] < / code > by serializing it in memory .