smengcl commented on a change in pull request #2713:
URL: https://github.com/apache/ozone/pull/2713#discussion_r723612131
##########
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:
Yup. Great idea. I should have done this in the first place.
--
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]