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/09/20 08:31:07 UTC

[GitHub] [iceberg] nastra commented on a diff in pull request #5802: Core: Reduce duplicated code in JSON Parsers

nastra commented on code in PR #5802:
URL: https://github.com/apache/iceberg/pull/5802#discussion_r975047073


##########
core/src/main/java/org/apache/iceberg/PartitionSpecParser.java:
##########
@@ -66,19 +65,7 @@ public static String toJson(UnboundPartitionSpec spec) {
   }
 
   public static String toJson(UnboundPartitionSpec spec, boolean pretty) {
-    try {
-      StringWriter writer = new StringWriter();
-      JsonGenerator generator = JsonUtil.factory().createGenerator(writer);
-      if (pretty) {
-        generator.useDefaultPrettyPrinter();
-      }
-      toJson(spec, generator);
-      generator.flush();
-      return writer.toString();
-
-    } catch (IOException e) {
-      throw new RuntimeIOException(e);
-    }
+    return JsonUtil.generate(gen -> toJson(spec, gen), pretty);

Review Comment:
   > BTW we have a bit duplicated code for parsing as well. I was changing it in https://github.com/apache/iceberg/pull/5048.
   
   ah interesting, you're right. Do you want to open maybe a separate PR for removing that part of duplicated code?



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