rdblue commented on a change in pull request #4294:
URL: https://github.com/apache/iceberg/pull/4294#discussion_r824991546



##########
File path: core/src/main/java/org/apache/iceberg/TableMetadataParser.java
##########
@@ -252,22 +248,7 @@ private static void toJson(TableMetadata metadata, 
JsonGenerator generator) thro
   private static void toJson(Map<String, SnapshotRef> refs, JsonGenerator 
generator) throws IOException {
     generator.writeObjectFieldStart(REFS);
     for (Map.Entry<String, SnapshotRef> refEntry : refs.entrySet()) {
-      generator.writeObjectFieldStart(refEntry.getKey());
-
-      SnapshotRef ref = refEntry.getValue();
-      generator.writeStringField(TYPE, 
ref.type().toString().toLowerCase(Locale.ROOT));
-      generator.writeNumberField(SNAPSHOT_ID, ref.snapshotId());
-      if (ref.maxRefAgeMs() != null) {
-        generator.writeNumberField(MAX_REF_AGE_MS, ref.maxRefAgeMs());
-      }
-      if (ref.maxSnapshotAgeMs() != null) {
-        generator.writeNumberField(MAX_SNAPSHOT_AGE_MS, 
ref.maxSnapshotAgeMs());
-      }
-      if (ref.minSnapshotsToKeep() != null) {
-        generator.writeNumberField(MIN_SNAPSHOTS_TO_KEEP, 
ref.minSnapshotsToKeep());
-      }
-
-      generator.writeEndObject();
+      SnapshotRefParser.toJson(refEntry.getKey(), refEntry.getValue(), 
generator);

Review comment:
       I think that the `writeObjectFieldStart` and `writeEndObject` should be 
here in this function. Moving it to `toJson` in the other class creates an 
implicit requirement on the state of the `JsonGenerator`. It _must_ be writing 
an object. We avoid depending on the state of objects passed in where possible, 
**especially** for methods that are public.
   
   Instead, the state of the generator should always be that it is ready to 
write any JSON value.




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