public static byte[] getBytes(Object o) {
        if (o instanceof String) {
            return ((String)o).getBytes();
        } else if (o instanceof byte[]) {
            return (byte[])o;
        } else if (o instanceof Serializable) {
            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            ObjectOutput out = null;
            try {
                out = new ObjectOutputStream(bos);
                out.writeObject(o);
                byte[] bytes = bos.toByteArray();
                return bytes;
            } catch(Exception e) {
                return null;
            } finally {
                try {
                    if (out != null) {
                        out.close();
                    }
                } catch (IOException ex) {
                    // ignore close exception
                }
                try {
                    bos.close();
                } catch (IOException ex) {
                    // ignore close exception
                }
            }
        }
        throw new RuntimeException("Fail to convert object to bytes");
    }