code: public static byte[] toByteArray( Serializable object )
  	{
  	    try
  	    {
              ByteArrayOutputStream buf = new ByteArrayOutputStream(1024);
              ObjectOutputStream objOut = new ObjectOutputStream(buf);
              objOut.writeObject(object);
              objOut.close();
              return buf.toByteArray();
  	    }
  	    catch (IOException e)
  	    {
  	        throw new IllegalArgumentException("Cannot serialize object : "+e.toString());
  	    }
  	}
docs: Object to byte array