code: public static byte[] serialize(final Object o, final boolean zip) throws IOException {
          final ByteArrayOutputStream baos = new ByteArrayOutputStream();
          OutputStream os = baos;
          ObjectOutputStream oos = null;
          try {
              if (zip) {
                  os = new GZIPOutputStream(os);
              }
              oos = new ObjectOutputStream(os);
              oos.writeObject(o);
              oos.flush();
          } finally {
              if (oos != null) {
                  oos.close();
              }
              os.close();
          }
  
          return baos.toByteArray();
      }
docs: serializes object to byte[]
  
  @param o   the object to serialize
  @param zip true if the data should be compressed
  @return the serialized bytes
  @throws IOException thrown when an error is encountered writing the data