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/09 22:19:35 UTC

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

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


##########
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:
   We can actually do shorter one w/ just `mapper.setVisibility(JsonMethod.FIELD, Visibility.ANY)` and so on



##########
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:
   We also need to handle `WithIsGetterVisibility` (for `is*` getters)



##########
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:
   You can do `CollectionUtils.toStream` for easier conversion



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