ArafatKhan2198 commented on code in PR #6500:
URL: https://github.com/apache/ozone/pull/6500#discussion_r1589738492


##########
hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/server/JsonUtils.java:
##########
@@ -116,4 +121,26 @@ public static <T> List<T> readFromFile(File file, Class<T> 
itemType)
     }
   }
 
+  /**
+   * Reads JSON content from a Reader and deserializes it into an array of the
+   * specified type.
+   */
+  public static <T> T[] readArrayFromReader(Reader reader, Class<T[]> 
valueType)
+      throws IOException {
+    return MAPPER.readValue(reader, valueType);
+  }
+
+  /**
+   * Converts a JsonNode into a Java object of the specified type.
+   * @param node The JsonNode to convert.
+   * @param valueType The target class of the Java object.
+   * @param <T> The type of the Java object.
+   * @return A Java object of type T, populated with data from the JsonNode.
+   * @throws IOException
+   */
+  public static <T> T treeToValue(JsonNode node, Class<T> valueType)
+      throws IOException {
+    return MAPPER.treeToValue(node, valueType);
+  }

Review Comment:
   Thanks for letting me know!
   I have made the changes.
   



##########
hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/keyvalue/KeyValueContainerMetadataInspector.java:
##########
@@ -181,55 +182,60 @@ public String process(ContainerData containerData, 
DatanodeStore store,
       return null;
     }
 
-    JsonObject containerJson = inspectContainer(kvData, store);
+    ObjectNode containerJson = inspectContainer(kvData, store);
     boolean correct = checkAndRepair(containerJson, kvData, store);
 
-    Gson gson = new GsonBuilder()
-        .setPrettyPrinting()
-        .serializeNulls()
-        .create();
-    String jsonReport = gson.toJson(containerJson);
-    if (log != null) {
-      if (correct) {
-        log.trace(jsonReport);
-      } else {
-        log.error(jsonReport);
+    ObjectMapper objectMapper = new ObjectMapper();
+    objectMapper.enable(
+        SerializationFeature.INDENT_OUTPUT);
+    String jsonReport = null;
+    try {
+      jsonReport = objectMapper.writeValueAsString(containerJson);
+      if (log != null) {
+        if (correct) {
+          log.trace(jsonReport);
+        } else {
+          log.error(jsonReport);
+        }
       }
+    } catch (Exception e) {
+      LOG.error("Error serializing container JSON", e);

Review Comment:
   Done!



-- 
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