code: public static <T extends Serializable> byte[] serializeIntoBytes(T obj) throws IOException {
      try (ByteArrayOutputStream bos = new ByteArrayOutputStream();
          ObjectOutputStream oos = new ObjectOutputStream(bos)) {
        oos.writeObject(obj);
        oos.flush();
        return bos.toByteArray();
      }
    }
docs: Serialize an object into a byte array.
  
  @param obj A {@link Serializable} object
  @return Byte serialization of input object
  @throws IOException if it fails to serialize the object