Updated Branches: refs/heads/bvt f4286088b -> 6637b8f16
api nested entity: skip null values when response is not embedded object When the response field doesn't have a nested object the earlier implementation would create empty lists in the returned JSON. This situation is avoided now. Signed-off-by: Prasanna Santhanam <t...@apache.org> Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/6637b8f1 Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/6637b8f1 Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/6637b8f1 Branch: refs/heads/bvt Commit: 6637b8f16054a1c37a98024d268d39748b509554 Parents: f428608 Author: Prasanna Santhanam <t...@apache.org> Authored: Wed Mar 27 22:12:24 2013 +0530 Committer: Prasanna Santhanam <t...@apache.org> Committed: Wed Mar 27 22:12:24 2013 +0530 ---------------------------------------------------------------------- .../api/response/ApiResponseResponse.java | 13 ++++++------- .../cloud/api/response/ApiResponseSerializer.java | 4 +--- 2 files changed, 7 insertions(+), 10 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cloudstack/blob/6637b8f1/plugins/api/discovery/src/org/apache/cloudstack/api/response/ApiResponseResponse.java ---------------------------------------------------------------------- diff --git a/plugins/api/discovery/src/org/apache/cloudstack/api/response/ApiResponseResponse.java b/plugins/api/discovery/src/org/apache/cloudstack/api/response/ApiResponseResponse.java index b536b32..1433879 100644 --- a/plugins/api/discovery/src/org/apache/cloudstack/api/response/ApiResponseResponse.java +++ b/plugins/api/discovery/src/org/apache/cloudstack/api/response/ApiResponseResponse.java @@ -16,9 +16,9 @@ // under the License. package org.apache.cloudstack.api.response; -import org.apache.cloudstack.api.ApiConstants; import com.cloud.serializer.Param; import com.google.gson.annotations.SerializedName; +import org.apache.cloudstack.api.ApiConstants; import org.apache.cloudstack.api.BaseResponse; import java.util.HashSet; @@ -37,10 +37,6 @@ public class ApiResponseResponse extends BaseResponse { @SerializedName(ApiConstants.RESPONSE) @Param(description="api response fields") private Set<ApiResponseResponse> apiResponse; - public ApiResponseResponse() { - apiResponse = new HashSet<ApiResponseResponse>(); - } - public void setName(String name) { this.name = name; } @@ -53,7 +49,10 @@ public class ApiResponseResponse extends BaseResponse { this.type = type; } - public void addApiResponse(ApiResponseResponse apiResponse) { - this.apiResponse.add(apiResponse); + public void addApiResponse(ApiResponseResponse childApiResponse) { + if(this.apiResponse == null) { + this.apiResponse = new HashSet<ApiResponseResponse>(); + } + this.apiResponse.add(childApiResponse); } } http://git-wip-us.apache.org/repos/asf/cloudstack/blob/6637b8f1/server/src/com/cloud/api/response/ApiResponseSerializer.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/api/response/ApiResponseSerializer.java b/server/src/com/cloud/api/response/ApiResponseSerializer.java index 4eaf3d5..965660a 100644 --- a/server/src/com/cloud/api/response/ApiResponseSerializer.java +++ b/server/src/com/cloud/api/response/ApiResponseSerializer.java @@ -21,7 +21,6 @@ import com.cloud.api.ApiResponseGsonHelper; import com.cloud.api.ApiServer; import com.cloud.utils.encoding.URLEncoder; import com.cloud.utils.exception.CloudRuntimeException; -import com.google.gson.ExclusionStrategy; import com.google.gson.Gson; import com.google.gson.annotations.SerializedName; import org.apache.cloudstack.api.ApiConstants; @@ -62,8 +61,7 @@ public class ApiResponseSerializer { public static String toJSONSerializedString(ResponseObject result) { if (result != null) { - ExclusionStrategy excludes = new EmptyFieldExclusionStrategy(); - Gson gson = ApiResponseGsonHelper.getBuilder().excludeFieldsWithModifiers(Modifier.TRANSIENT).setExclusionStrategies(excludes).create(); + Gson gson = ApiResponseGsonHelper.getBuilder().excludeFieldsWithModifiers(Modifier.TRANSIENT).create(); StringBuilder sb = new StringBuilder();