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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to