public static byte[] toByteArray(Serializable object)
	{
		ByteArrayOutputStream bOS = null;
		ObjectOutput oOS = null;
		
		byte[] bytes = null;
		
		try { // Write object to a byte[] using ByteArrayOutputStream and ObjectOutputStream
			bOS = new ByteArrayOutputStream ();
			oOS = new ObjectOutputStream (bOS);
			oOS.writeObject (object);
			
			bytes = bOS.toByteArray ();
		} catch (IOException e) {
			e.printStackTrace ();
		} finally { // Close ByteArrayOutputStream and ObjectOutputStream
			if (bOS != null) {
				try {
					bOS.close ();
				} catch (IOException ex) {}
			}
			
			if (oOS != null) {
				try {
					oOS.close ();
				} catch (IOException ex) {}
			}
		}
		
		return bytes;
	}