findepi commented on code in PR #5802:
URL: https://github.com/apache/iceberg/pull/5802#discussion_r975038691
##########
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:
Nice!
BTW we have a bit duplicated code for parsing as well. I was changing it in
https://github.com/apache/iceberg/pull/5048.
BTW 2: i'd use `generator` instead of `gen`. That's how it's usually called,
so it will be more familiar
--
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]