Skip to content

Commit 10bb819

Browse files
committed
fix: Only include nulls in serialization when processing API responses
1 parent 111ea91 commit 10bb819

File tree

2 files changed

+4
-5
lines changed

2 files changed

+4
-5
lines changed

src/main/java/com/ibm/cloud/sdk/core/http/RequestBuilder.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
*/
1313
package com.ibm.cloud.sdk.core.http;
1414

15+
import com.google.gson.Gson;
1516
import com.google.gson.JsonObject;
1617
import com.ibm.cloud.sdk.core.service.BaseService;
1718
import com.ibm.cloud.sdk.core.util.GsonSingleton;
@@ -333,12 +334,11 @@ public RequestBuilder bodyContent(InputStream stream, String contentType) {
333334
public RequestBuilder bodyContent(String contentType, Object jsonContent, Object jsonPatchContent,
334335
InputStream nonJsonContent) {
335336
if (contentType != null) {
337+
Gson requestGson = GsonSingleton.getGson().newBuilder().serializeNulls().create();
336338
if (BaseService.isJsonMimeType(contentType)) {
337-
this.bodyContent(
338-
GsonSingleton.getGson().toJsonTree(jsonContent).getAsJsonObject().toString(), contentType);
339+
this.bodyContent(requestGson.toJsonTree(jsonContent).getAsJsonObject().toString(), contentType);
339340
} else if (BaseService.isJsonPatchMimeType(contentType)) {
340-
this.bodyContent(
341-
GsonSingleton.getGson().toJsonTree(jsonPatchContent).getAsJsonObject().toString(), contentType);
341+
this.bodyContent(requestGson.toJsonTree(jsonPatchContent).getAsJsonObject().toString(), contentType);
342342
} else {
343343
this.bodyContent(nonJsonContent, contentType);
344344
}

src/main/java/com/ibm/cloud/sdk/core/util/GsonSingleton.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ private static Gson createGson(Boolean prettyPrint) {
4545
builder.setPrettyPrinting();
4646
}
4747
builder.disableHtmlEscaping();
48-
builder.serializeNulls();
4948
return builder.create();
5049
}
5150

0 commit comments

Comments
 (0)