diff --git a/samples/client/petstore/java/jersey2/pom.xml b/samples/client/petstore/java/jersey2/pom.xml
index 0881cc29374..6b0ba2cba08 100644
--- a/samples/client/petstore/java/jersey2/pom.xml
+++ b/samples/client/petstore/java/jersey2/pom.xml
@@ -124,7 +124,12 @@
jersey-media-multipart
${jersey-version}
-
+
+ org.glassfish.jersey.media
+ jersey-media-json-jackson
+ 2.22.1
+
+
com.fasterxml.jackson.core
diff --git a/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/ApiClient.java b/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/ApiClient.java
index c5c74cc11e4..4ca24fbabb0 100644
--- a/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/ApiClient.java
+++ b/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/ApiClient.java
@@ -6,6 +6,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.GenericType;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
@@ -29,20 +30,18 @@ import java.util.TimeZone;
import java.net.URLEncoder;
-import java.io.IOException;
import java.io.File;
import java.io.UnsupportedEncodingException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
-import java.text.ParseException;
import io.swagger.client.auth.Authentication;
import io.swagger.client.auth.HttpBasicAuth;
import io.swagger.client.auth.ApiKeyAuth;
import io.swagger.client.auth.OAuth;
-@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-12-09T16:27:55.818+08:00")
+@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-12-09T12:31:44.572-05:00")
public class ApiClient {
private Client client;
private Map hostMap = new HashMap();
@@ -411,18 +410,39 @@ public class ApiClient {
* Serialize the given Java object into string entity according the given
* Content-Type (only JSON is supported for now).
*/
- public Entity serialize(Object obj, String contentType) throws ApiException {
- if (isJsonMime(contentType)) {
- return Entity.json(json.serialize(obj));
+ public Entity> serialize(Object obj, Map formParams, String contentType) throws ApiException {
+ Entity> entity = null;
+ if (contentType.startsWith("multipart/form-data")) {
+ MultiPart multiPart = new MultiPart();
+ for (Entry param: formParams.entrySet()) {
+ if (param.getValue() instanceof File) {
+ File file = (File) param.getValue();
+ FormDataContentDisposition contentDisp = FormDataContentDisposition.name(param.getKey())
+ .fileName(file.getName()).size(file.length()).build();
+ multiPart.bodyPart(new FormDataBodyPart(contentDisp, file, MediaType.APPLICATION_OCTET_STREAM_TYPE));
+ } else {
+ FormDataContentDisposition contentDisp = FormDataContentDisposition.name(param.getKey()).build();
+ multiPart.bodyPart(new FormDataBodyPart(contentDisp, parameterToString(param.getValue())));
+ }
+ }
+ entity = Entity.entity(multiPart, MediaType.MULTIPART_FORM_DATA_TYPE);
+ } else if (contentType.startsWith("application/x-www-form-urlencoded")) {
+ Form form = new Form();
+ for (Entry param: formParams.entrySet()) {
+ form.param(param.getKey(), parameterToString(param.getValue()));
+ }
+ entity = Entity.entity(form, MediaType.APPLICATION_FORM_URLENCODED_TYPE);
} else {
- throw new ApiException(400, "can not serialize object into Content-Type: " + contentType);
+ // We let jersey handle the serialization
+ entity = Entity.entity(obj, contentType);
}
+ return entity;
}
/**
* Deserialize response body to Java object according to the Content-Type.
*/
- public T deserialize(Response response, TypeRef returnType) throws ApiException {
+ public T deserialize(Response response, GenericType returnType) throws ApiException {
String contentType = null;
List