code: public static byte[] dataSerialize(Object data) throws IOException {
  
          if (isParseable(data.getClass())) {
              return format(data).getBytes();
          }
  
          // serialize the data
          ByteArrayOutputStream bout = new ByteArrayOutputStream();
          ObjectOutputStream oout = new ObjectOutputStream(bout);
          Object obj = data;
          if (data instanceof Map) {
              Hashtable<Object, Object> ht = new Hashtable<Object, Object>();
              @SuppressWarnings("unchecked")
              Iterator<Entry<Object, Object>> it = ((Map<Object, Object>)data).entrySet().iterator();
              while (it.hasNext()) {
                  Entry<Object, Object> entry = it.next();
                  if ((entry.getKey() != null) && (entry.getValue() != null)) {
                      ht.put(entry.getKey(), entry.getValue());
                  }
              }
              obj = ht;
          }
          oout.writeObject(obj);
          oout.close();
          return bout.toByteArray();
      }
docs: Serialize the given data.<p>
  
  @param data the data to serialize
  
  @return byte[] the serailized data
  
  @throws IOException if something goes wrong