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


##########
hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/server/JsonUtils.java:
##########
@@ -79,14 +81,18 @@ public static ObjectNode createObjectNode(Object next) {
     return MAPPER.valueToTree(next);
   }
 
+  public static JsonNode valueToJsonNode(Object value) {
+    return MAPPER.valueToTree(value);
+  }
+
   public static JsonNode readTree(String content) throws IOException {
     return MAPPER.readTree(content);
   }
 
-  public static List<HashMap<String, Object>> readTreeAsListOfMaps(String json)
+  public static ArrayList<LinkedHashMap<String, Object>> 
readTreeAsListOfMaps(String json)

Review Comment:
   We should replace `ArrayList` with `List` with `ArrayList` but the other way.
   
   BTW, this method is only used in tests.  Create a `JsonTestUtils` in 
`src/test` and then move the test methods there..



##########
hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/server/JsonUtils.java:
##########
@@ -79,14 +81,18 @@ public static ObjectNode createObjectNode(Object next) {
     return MAPPER.valueToTree(next);
   }
 
+  public static JsonNode valueToJsonNode(Object value) {

Review Comment:
   Move it to `src/test`.



##########
hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/server/JsonUtils.java:
##########
@@ -116,4 +122,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)

Review Comment:
   Move it to test.



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