Skip to content

Commit

Permalink
fix: Only include nulls in serialization when processing API responses
Browse files Browse the repository at this point in the history
  • Loading branch information
lpatino10 committed Mar 25, 2019
1 parent 111ea91 commit 10bb819
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
8 changes: 4 additions & 4 deletions src/main/java/com/ibm/cloud/sdk/core/http/RequestBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
*/
package com.ibm.cloud.sdk.core.http;

import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.ibm.cloud.sdk.core.service.BaseService;
import com.ibm.cloud.sdk.core.util.GsonSingleton;
Expand Down Expand Up @@ -333,12 +334,11 @@ public RequestBuilder bodyContent(InputStream stream, String contentType) {
public RequestBuilder bodyContent(String contentType, Object jsonContent, Object jsonPatchContent,
InputStream nonJsonContent) {
if (contentType != null) {
Gson requestGson = GsonSingleton.getGson().newBuilder().serializeNulls().create();
if (BaseService.isJsonMimeType(contentType)) {
this.bodyContent(
GsonSingleton.getGson().toJsonTree(jsonContent).getAsJsonObject().toString(), contentType);
this.bodyContent(requestGson.toJsonTree(jsonContent).getAsJsonObject().toString(), contentType);
} else if (BaseService.isJsonPatchMimeType(contentType)) {
this.bodyContent(
GsonSingleton.getGson().toJsonTree(jsonPatchContent).getAsJsonObject().toString(), contentType);
this.bodyContent(requestGson.toJsonTree(jsonPatchContent).getAsJsonObject().toString(), contentType);
} else {
this.bodyContent(nonJsonContent, contentType);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ private static Gson createGson(Boolean prettyPrint) {
builder.setPrettyPrinting();
}
builder.disableHtmlEscaping();
builder.serializeNulls();
return builder.create();
}

Expand Down

0 comments on commit 10bb819

Please sign in to comment.