public static byte[] writeObject(Object object) throws IOException {
  ByteArrayOutputStream buffer=new ByteArrayOutputStream();
  ObjectOutputStream out=new ObjectOutputStream(buffer);
  out.writeObject(object);
  out.close();
  return buffer.toByteArray();
}

public static byte [ ] writeObject ( Object object ) throws IOException { ByteArrayOutputStream buffer = new ByteArrayOutputStream ( ) ; ObjectOutputStream out = new ObjectOutputStream ( buffer ) ; out . writeObject ( object ) ; out . close ( ) ; return buffer . toByteArray ( ) ; }
serialize an object to a bytearray
