Skip to content

Only include nulls in serialization when processing API responses #20

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,8 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>${compiler-plugin-version}</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
Expand Down
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
2 changes: 1 addition & 1 deletion src/main/java/com/ibm/cloud/sdk/core/http/ServiceCall.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public interface ServiceCall<T> {
*
* @param callback the callback
*/
void enqueue(ServiceCallback<? super T> callback);
void enqueue(ServiceCallback<T> callback);

/**
* Reactive request using the RxJava 2 library. See https://github.com/ReactiveX/RxJava. In addition, the wrapped
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ public com.ibm.cloud.sdk.core.http.Response<T> execute() {
}

@Override
public void enqueue(final ServiceCallback<? super T> callback) {
public void enqueue(final ServiceCallback<T> callback) {
call.enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ private boolean isRefreshTokenExpired() {
* @param request the request for the IAM API
* @return object containing requested IAM token information
*/
private IamToken callIamApi(Request request) {
private IamToken callIamApi(final Request request) {
final IamToken[] returnToken = new IamToken[1];

Thread iamApiCall = new Thread(new Runnable() {
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