You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by mu...@apache.org on 2012/12/06 09:09:07 UTC

[10/100] [abbrv] git commit: Fixed json response to return "size" parameter (resources count in the system) when pageSize=0 is specified

Fixed json response to return "size" parameter (resources count in the system) when pageSize=0 is specified


Project: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/commit/29149858
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/tree/29149858
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/diff/29149858

Branch: refs/heads/events-framework
Commit: 2914985837929c49aef10387b6bd57123a836b8b
Parents: 6d9cafb
Author: Alena Prokharchyk <al...@citrix.com>
Authored: Wed Nov 14 14:04:41 2012 -0800
Committer: Alena Prokharchyk <al...@citrix.com>
Committed: Wed Nov 14 15:01:48 2012 -0800

----------------------------------------------------------------------
 .../cloud/api/response/ApiResponseSerializer.java  |   22 ++++++++++-----
 1 files changed, 15 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/29149858/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 dc15763..4be5dfa 100644
--- a/server/src/com/cloud/api/response/ApiResponseSerializer.java
+++ b/server/src/com/cloud/api/response/ApiResponseSerializer.java
@@ -73,24 +73,32 @@ public class ApiResponseSerializer {
             sb.append("{ \"").append(result.getResponseName()).append("\" : ");
             if (result instanceof ListResponse) {
                 List<? extends ResponseObject> responses = ((ListResponse) result).getResponses();
+                Integer count = ((ListResponse) result).getCount();
+                boolean nonZeroCount = (count != null && count.longValue() != 0);
+                if (nonZeroCount) {
+                    sb.append("{ \"").append(ApiConstants.COUNT).append("\":").append(count);
+                }
+                
                 if ((responses != null) && !responses.isEmpty()) {
-
-                    Integer count = ((ListResponse) result).getCount();
                     String jsonStr = gson.toJson(responses.get(0));                    
                     jsonStr = unescape(jsonStr);
 
-                    if (count != null && count != 0) {
-                        sb.append("{ \"").append(ApiConstants.COUNT).append("\":").append(count).append(" ,\"").
-                        append(responses.get(0).getObjectName()).append("\" : [  ").append(jsonStr);
+                    if (nonZeroCount) {
+                        sb.append(" ,\"").append(responses.get(0).getObjectName()).append("\" : [  ").append(jsonStr);
                     }
+                    
                     for (int i = 1; i < ((ListResponse) result).getResponses().size(); i++) {
                         jsonStr = gson.toJson(responses.get(i));
                         jsonStr = unescape(jsonStr);
                         sb.append(", ").append(jsonStr);
                     }
                     sb.append(" ] }");
-                } else {
-                    sb.append("{ }");
+                } else  {
+                    if (!nonZeroCount){ 
+                        sb.append("{");
+                    }
+                    
+                    sb.append(" }");
                 }
             } else if (result instanceof SuccessResponse) {
                 sb.append("{ \"success\" : \"").append(((SuccessResponse) result).getSuccess()).append("\"} ");