code: public Object serialize(Object obj, String contentType, Map<String, Object> formParams) throws ApiException {
      if (contentType.startsWith("multipart/form-data")) {
        FormDataMultiPart mp = new FormDataMultiPart();
        for (Entry<String, Object> param : formParams.entrySet()) {
          if (param.getValue() instanceof List && !((List) param.getValue()).isEmpty()
                  && ((List) param.getValue()).get(0) instanceof File) {
            @SuppressWarnings("unchecked")
            List<File> files = (List<File>) param.getValue();
            for (File file : files) {
              mp.bodyPart(new FileDataBodyPart(param.getKey(), file, MediaType.APPLICATION_OCTET_STREAM_TYPE));
            }
          } else if (param.getValue() instanceof File) {
            File file = (File) param.getValue();
            mp.bodyPart(new FileDataBodyPart(param.getKey(), file, MediaType.APPLICATION_OCTET_STREAM_TYPE));
          } else {
            mp.field(param.getKey(), parameterToString(param.getValue()), MediaType.MULTIPART_FORM_DATA_TYPE);
          }
        }
        return mp;
      } else if (contentType.startsWith("application/x-www-form-urlencoded")) {
        return this.getXWWWFormUrlencodedParams(formParams);
      } else {
        // We let Jersey attempt to serialize the body
        return obj;
      }
    }
docs: Serialize the given Java object into string according the given
  Content-Type (only JSON is supported for now).
  
  @param obj         Object
  @param contentType Content type
  @param formParams  Form parameters
  @return Object
  @throws ApiException API exception