code: public static byte[] serialize(Object obj) throws IOException {
      if (obj == null) {
        return null;
      }
      try (ByteArrayOutputStream b = new ByteArrayOutputStream()) {
        try (ObjectOutputStream o = new ObjectOutputStream(b)) {
          o.writeObject(obj);
        }
        return b.toByteArray();
      }
    }
docs: Serializes an object into a byte array. When the object is null, returns null.
  
  @param obj the object to serialize
  @return the serialized bytes
  @throws IOException if the serialization fails