Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add serialize to string method
  • Loading branch information
wing328 committed Apr 27, 2020
commit 0ea19e5aa0166e1fcf03d31e31b0df4c0aa85f13
Original file line number Diff line number Diff line change
Expand Up @@ -703,6 +703,34 @@ public Entity<?> serialize(Object obj, Map<String, Object> formParams, String co
return entity;
}

/**
* Serialize the given Java object into string according the given
* Content-Type (only JSON, HTTP form is supported for now).
* @param obj Object
* @param formParams Form parameters
* @param contentType Context type
* @return String
* @throws Exception exception
*/
public String serializeToString(Object obj, Map<String, Object> formParams, String contentType) throws Exception {
if (contentType.startsWith("multipart/form-data")) {
throw new ApiException("multipart/form-data not yet supported for serializeToString (http signature authentication)");
} else if (contentType.startsWith("application/x-www-form-urlencoded")) {
String formString = "";
for (Entry<String, Object> param: formParams.entrySet()) {
formString = param.getKey() + "=" + URLEncoder.encode(parameterToString(param.getValue()), "UTF-8") + "&";
}

if (formString.length() == 0) { // empty string
return formString;
} else {
return formString.substring(0, formString.length() - 1);
}
} else {
return json.getMapper().writeValueAsString(obj);
}
}

public AbstractOpenApiSchema deserializeSchemas(Response response, AbstractOpenApiSchema schema) throws ApiException{

Object result = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,6 @@ public void setDateFormat(DateFormat dateFormat) {
public ObjectMapper getContext(Class<?> type) {
return mapper;
}

public ObjectMapper getMapper() { return mapper; }
}