You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hudi.apache.org by GitBox <gi...@apache.org> on 2022/09/12 22:53:27 UTC

[GitHub] [hudi] yihua commented on a diff in pull request #6646: [HUDI-4825] Remove redundant fields in serialized commit metadata in JSON

yihua commented on code in PR #6646:
URL: https://github.com/apache/hudi/pull/6646#discussion_r968904595


##########
hudi-common/src/main/java/org/apache/hudi/common/util/JsonUtils.java:
##########
@@ -29,7 +28,14 @@ public class JsonUtils {
   private static final ObjectMapper MAPPER = new ObjectMapper();
   static {
     MAPPER.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
-    MAPPER.setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY);
+    // We need to exclude custom getters, setters and creators which can use member fields
+    // to derive new fields, so that they are not included in the serialization
+    MAPPER.setVisibility(
+        MAPPER.getSerializationConfig().getDefaultVisibilityChecker()

Review Comment:
   Fixed.



##########
hudi-common/src/main/java/org/apache/hudi/common/util/JsonUtils.java:
##########
@@ -29,7 +28,14 @@ public class JsonUtils {
   private static final ObjectMapper MAPPER = new ObjectMapper();
   static {
     MAPPER.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
-    MAPPER.setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY);
+    // We need to exclude custom getters, setters and creators which can use member fields
+    // to derive new fields, so that they are not included in the serialization
+    MAPPER.setVisibility(
+        MAPPER.getSerializationConfig().getDefaultVisibilityChecker()
+            .withFieldVisibility(JsonAutoDetect.Visibility.ANY)
+            .withGetterVisibility(JsonAutoDetect.Visibility.NONE)
+            .withSetterVisibility(JsonAutoDetect.Visibility.NONE)

Review Comment:
   Makes sense.  Fixed.



##########
hudi-common/src/test/java/org/apache/hudi/common/model/TestHoodieCommitMetadata.java:
##########
@@ -34,6 +40,33 @@
  */
 public class TestHoodieCommitMetadata {
 
+  private static final List<String> EXPECTED_FIELD_NAMES = Arrays.asList(
+      "partitionToWriteStats", "compacted", "extraMetadata", "operationType");
+
+  public static void verifyMetadataFieldNames(
+      HoodieCommitMetadata commitMetadata, List<String> expectedFieldNameList)
+      throws IOException {
+    String serializedCommitMetadata = commitMetadata.toJsonString();
+    Iterator<String> fieldNameIterator = JsonUtils.getObjectMapper()

Review Comment:
   Fixed.



-- 
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: commits-unsubscribe@hudi.apache.org

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