Java client: decouple JSON handling

This commit is contained in:
xhh
2015-08-04 15:47:55 +08:00
parent 112a7ec8c1
commit bfb4629ab7
6 changed files with 124 additions and 87 deletions

View File

@@ -4,6 +4,7 @@ import {{invokerPackage}}.ApiException;
import {{invokerPackage}}.ApiClient;
import {{invokerPackage}}.Configuration;
import {{invokerPackage}}.Pair;
import {{invokerPackage}}.TypeRef;
import {{modelPackage}}.*;
@@ -83,18 +84,13 @@ public class {{classname}} {
};
final String contentType = apiClient.selectHeaderContentType(contentTypes);
try {
String[] authNames = new String[] { {{#authMethods}}"{{name}}"{{#hasMore}}, {{/hasMore}}{{/authMethods}} };
String response = apiClient.invokeAPI(path, "{{httpMethod}}", queryParams, postBody, headerParams, formParams, accept, contentType, authNames);
if(response != null){
return {{#returnType}}({{{returnType}}}) apiClient.deserialize(response, "{{returnContainer}}", {{returnBaseType}}.class){{/returnType}};
}
else {
return {{#returnType}}null{{/returnType}};
}
} catch (ApiException ex) {
throw ex;
}
String[] authNames = new String[] { {{#authMethods}}"{{name}}"{{#hasMore}}, {{/hasMore}}{{/authMethods}} };
{{#returnType}}
TypeRef returnType = new TypeRef<{{{returnType}}}>() {};
return apiClient.invokeAPI(path, "{{httpMethod}}", queryParams, postBody, headerParams, formParams, accept, contentType, authNames, returnType);
{{/returnType}}{{^returnType}}
apiClient.invokeAPI(path, "{{httpMethod}}", queryParams, postBody, headerParams, formParams, accept, contentType, authNames, null);
{{/returnType}}
}
{{/operation}}
}