code: public static byte[] serialize( Object obj ) throws IOException {
          try (ByteArrayOutputStream bos = new ByteArrayOutputStream()) {
              ObjectOutputStream out = new ObjectOutputStream(bos);
              out.writeObject(obj);
              out.close();
              return bos.toByteArray();
          }
      }
docs: Serialize an Object to disk.
  
  @param obj
  the object to serialize.
  @return the bytes.
  @throws IOException