CLOUDSTACK-8155: Remove unwanted whitespaces from json response This removes extra whitespaces from the JSON serialized response. After the fix, tested to work with: - Present UI - CloudMonkey - Old buggy json parsers
Signed-off-by: Rohit Yadav <[email protected]> (cherry picked from commit 921ad057def3015cda9d9f5861c9be29a88b148e) Signed-off-by: Rohit Yadav <[email protected]> Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/185f7e01 Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/185f7e01 Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/185f7e01 Branch: refs/heads/master Commit: 185f7e0152e3250a19b864a221ee7bb6cc405b51 Parents: b7b3a4f Author: Rohit Yadav <[email protected]> Authored: Wed Jan 14 02:33:34 2015 +0530 Committer: Rohit Yadav <[email protected]> Committed: Wed Jan 14 02:43:54 2015 +0530 ---------------------------------------------------------------------- .../api/response/ApiResponseSerializer.java | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cloudstack/blob/185f7e01/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 a32bd56..19d2671 100644 --- a/server/src/com/cloud/api/response/ApiResponseSerializer.java +++ b/server/src/com/cloud/api/response/ApiResponseSerializer.java @@ -79,13 +79,13 @@ public class ApiResponseSerializer { StringBuilder sb = new StringBuilder(); - sb.append("{ \"").append(result.getResponseName()).append("\" : "); + 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); + sb.append("{\"").append(ApiConstants.COUNT).append("\":").append(count); } if ((responses != null) && !responses.isEmpty()) { @@ -93,24 +93,24 @@ public class ApiResponseSerializer { jsonStr = unescape(jsonStr); if (nonZeroCount) { - sb.append(" ,\"").append(responses.get(0).getObjectName()).append("\" : [ ").append(jsonStr); + 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(",").append(jsonStr); } - sb.append(" ] }"); + sb.append("]}"); } else { if (!nonZeroCount) { sb.append("{"); } - sb.append(" }"); + sb.append("}"); } } else if (result instanceof SuccessResponse) { - sb.append("{ \"success\" : \"").append(((SuccessResponse)result).getSuccess()).append("\"} "); + sb.append("{\"success\":\"").append(((SuccessResponse)result).getSuccess()).append("\"}"); } else if (result instanceof ExceptionResponse) { String jsonErrorText = gson.toJson(result); jsonErrorText = unescape(jsonErrorText); @@ -122,13 +122,13 @@ public class ApiResponseSerializer { if (result instanceof AsyncJobResponse || result instanceof CreateCmdResponse || result instanceof AuthenticationCmdResponse) { sb.append(jsonStr); } else { - sb.append(" { \"").append(result.getObjectName()).append("\" : ").append(jsonStr).append(" } "); + sb.append("{\"").append(result.getObjectName()).append("\":").append(jsonStr).append("}"); } } else { - sb.append("{ }"); + sb.append("{}"); } } - sb.append(" }"); + sb.append("}"); return sb.toString(); } return null;
