code: public static byte[] serialize(Object obj) {
          try(ByteArrayOutputStream bos = new ByteArrayOutputStream();
              ObjectOutputStream oos = new ObjectOutputStream(bos)) {
              oos.writeObject(obj);
              return bos.toByteArray();
          } 
          catch (IOException ex) {
              throw new UncheckedIOException(ex);
          }
      }
docs: Serialized the Object to byte array.
  
  @param obj
  @return