You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@iceberg.apache.org by GitBox <gi...@apache.org> on 2022/02/04 00:24:49 UTC

[GitHub] [iceberg] kbendick commented on a change in pull request #4037: REST Catalog - Initial request / response objects and Jackson-based SerDe module for some components

kbendick commented on a change in pull request #4037:
URL: https://github.com/apache/iceberg/pull/4037#discussion_r799075359



##########
File path: core/src/main/java/org/apache/iceberg/util/JsonUtil.java
##########
@@ -117,6 +127,31 @@ public static String getStringOrNull(String property, JsonNode node) {
     return builder.build();
   }
 
+  public static Map<String, String> getStringMapOrNull(String property, JsonNode node) {
+    if (!node.has(property)) {
+      return null;
+    }
+
+    JsonNode pNode = node.get(property);
+    if (pNode == null || pNode.isNull()) {
+      return null;
+    }
+
+    Preconditions.checkArgument(pNode.isObject(),
+        "Cannot parse %s from non-object value: %s", property, pNode);
+    return buildStringMapFromJsonNodeObject(pNode);
+  }
+
+  private static Map<String, String> buildStringMapFromJsonNodeObject(JsonNode pNode) {
+    ImmutableMap.Builder<String, String> builder = ImmutableMap.builder();
+    Iterator<String> fields = pNode.fieldNames();
+    while (fields.hasNext()) {
+      String field = fields.next();
+      builder.put(field, getString(field, pNode));
+    }
+    return builder.build();

Review comment:
       This function is written such that it can be used in `getStringMap` and the differences between `getStringMap` and `getStringMapOrNull` would be in precondition checks, but I chose not to make that change to the existing code for now.




-- 
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@iceberg.apache.org

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



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