danielcweeks commented on code in PR #5178:
URL: https://github.com/apache/iceberg/pull/5178#discussion_r912270804
##########
core/src/main/java/org/apache/iceberg/util/JsonUtil.java:
##########
@@ -50,6 +52,55 @@ public static ObjectMapper mapper() {
return MAPPER;
}
+ @FunctionalInterface
+ public interface ToJson {
+ void generate(JsonGenerator gen) throws IOException;
+ }
+
+ /**
+ * Helper for writing JSON with a JsonGenerator.
+ *
+ * @param toJson a function to produce JSON using a JsonGenerator
+ * @param pretty whether to pretty-print JSON for readability
+ * @return a JSON string produced from the generator
+ */
+ public static String generate(ToJson toJson, boolean pretty) {
+ try {
+ StringWriter writer = new StringWriter();
+ JsonGenerator generator = JsonUtil.factory().createGenerator(writer);
Review Comment:
The JsonGenerator is closable, so we should probably be using TWR or closing
with finally.
--
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]