diff --git a/modules/openapi-generator/src/main/resources/Java/libraries/resteasy/ApiClient.mustache b/modules/openapi-generator/src/main/resources/Java/libraries/resteasy/ApiClient.mustache index 45a49cdf819..07c079e8922 100644 --- a/modules/openapi-generator/src/main/resources/Java/libraries/resteasy/ApiClient.mustache +++ b/modules/openapi-generator/src/main/resources/Java/libraries/resteasy/ApiClient.mustache @@ -33,6 +33,7 @@ import {{javaxPackage}}.ws.rs.client.Entity; import {{javaxPackage}}.ws.rs.client.Invocation; import {{javaxPackage}}.ws.rs.client.WebTarget; import {{javaxPackage}}.ws.rs.core.Form; +import {{javaxPackage}}.ws.rs.core.GenericEntity; import {{javaxPackage}}.ws.rs.core.GenericType; import {{javaxPackage}}.ws.rs.core.MediaType; import {{javaxPackage}}.ws.rs.core.Response; @@ -497,15 +498,16 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} { if (param.getValue() instanceof File) { File file = (File) param.getValue(); try { - multipart.addFormData(param.getValue().toString(),new FileInputStream(file),MediaType.APPLICATION_OCTET_STREAM_TYPE); + multipart.addFormData(param.getKey(),new FileInputStream(file),MediaType.APPLICATION_OCTET_STREAM_TYPE); } catch (FileNotFoundException e) { throw new ApiException("Could not serialize multipart/form-data "+e.getMessage()); } } else { - multipart.addFormData(param.getValue().toString(),param.getValue().toString(),MediaType.APPLICATION_OCTET_STREAM_TYPE); + multipart.addFormData(param.getKey(),param.getValue().toString(),MediaType.APPLICATION_OCTET_STREAM_TYPE); } } - entity = Entity.entity(multipart.getFormData(), MediaType.MULTIPART_FORM_DATA_TYPE); + GenericEntity genericEntity = new GenericEntity(multipart) { }; + entity = Entity.entity(genericEntity, MediaType.MULTIPART_FORM_DATA_TYPE); } else if (contentType.startsWith("application/x-www-form-urlencoded")) { Form form = new Form(); for (Entry param: formParams.entrySet()) { diff --git a/samples/client/petstore/java/resteasy/src/main/java/org/openapitools/client/ApiClient.java b/samples/client/petstore/java/resteasy/src/main/java/org/openapitools/client/ApiClient.java index 718adc4771c..2f1b1630926 100644 --- a/samples/client/petstore/java/resteasy/src/main/java/org/openapitools/client/ApiClient.java +++ b/samples/client/petstore/java/resteasy/src/main/java/org/openapitools/client/ApiClient.java @@ -31,6 +31,7 @@ import javax.ws.rs.client.Entity; import javax.ws.rs.client.Invocation; import javax.ws.rs.client.WebTarget; import javax.ws.rs.core.Form; +import javax.ws.rs.core.GenericEntity; import javax.ws.rs.core.GenericType; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; @@ -500,7 +501,8 @@ public class ApiClient extends JavaTimeFormatter { multipart.addFormData(param.getValue().toString(),param.getValue().toString(),MediaType.APPLICATION_OCTET_STREAM_TYPE); } } - entity = Entity.entity(multipart.getFormData(), MediaType.MULTIPART_FORM_DATA_TYPE); + GenericEntity genericEntity = new GenericEntity(multipart) { }; + entity = Entity.entity(genericEntity, MediaType.MULTIPART_FORM_DATA_TYPE); } else if (contentType.startsWith("application/x-www-form-urlencoded")) { Form form = new Form(); for (Entry param: formParams.entrySet()) {