You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@ozone.apache.org by GitBox <gi...@apache.org> on 2021/10/06 17:04:28 UTC

[GitHub] [ozone] errose28 commented on a change in pull request #2713: HDDS-5824. `ozone sh volume/bucket/key list` should print valid JSON array

errose28 commented on a change in pull request #2713:
URL: https://github.com/apache/ozone/pull/2713#discussion_r723505476



##########
File path: hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/shell/Handler.java
##########
@@ -118,6 +119,29 @@ protected void printObjectAsJson(Object o) throws IOException {
     out().println(JsonUtils.toJsonStringWithDefaultPrettyPrinter(o));
   }
 
+  protected String objectToJsonString(Object o) throws IOException {
+    return JsonUtils.toJsonStringWithDefaultPrettyPrinter(o);
+  }
+
+  /**
+   * Print the results in the iterator as a valid JSON array to out().
+   * @return Number of entries actually printed.
+   */
+  protected int printAsJsonArray(Iterator<?> iterator, int limit)
+      throws IOException {
+    int counter = 0;
+    out().print("[ ");
+    while (limit > counter && iterator.hasNext()) {
+      if (counter > 0) {
+        out().print(", ");
+      }
+      out().print(objectToJsonString(iterator.next()));
+      counter++;
+    }
+    out().println(" ]");

Review comment:
       Can we build the list using jackson in `JsonUtils` instead of mixing library generated json with manually generated json? JsonUtil has a `toJsonList` function but its actually a deserializer, not a serializer as the name implies. It also looks unused. Maybe we can make to `toJsonList` actually serialize a list of objects and use that here instead.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org