public static byte[] getBytes(Serializable data) {
        ObjectOutput out = null;
        byte[] res = null;
        if (data instanceof String) {
            return ((String) data).getBytes();
        }
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        try {
            out = new ObjectOutputStream(bos);
            out.writeObject(data);
            res = bos.toByteArray();
        } catch (IOException e) {
            return null;
        } finally {
            try {
                if (out != null) {
                    out.close();
                }
                bos.close();
            } catch (IOException e) {

            }
        }
        return res;
    }