Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
yihua committed Sep 12, 2022
1 parent c700472 commit 34f209d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package org.apache.hudi.common.util;

import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.PropertyAccessor;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;

Expand All @@ -30,12 +31,11 @@ public class JsonUtils {
MAPPER.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
// 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)
.withCreatorVisibility(JsonAutoDetect.Visibility.NONE));
MAPPER.setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY);
MAPPER.setVisibility(PropertyAccessor.GETTER, JsonAutoDetect.Visibility.NONE);
MAPPER.setVisibility(PropertyAccessor.IS_GETTER, JsonAutoDetect.Visibility.NONE);
MAPPER.setVisibility(PropertyAccessor.SETTER, JsonAutoDetect.Visibility.NONE);
MAPPER.setVisibility(PropertyAccessor.CREATOR, JsonAutoDetect.Visibility.NONE);
}

public static ObjectMapper getObjectMapper() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,14 @@
package org.apache.hudi.common.model;

import org.apache.hudi.common.testutils.HoodieTestUtils;
import org.apache.hudi.common.util.CollectionUtils;
import org.apache.hudi.common.util.FileIOUtils;
import org.apache.hudi.common.util.JsonUtils;

import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.stream.Collectors;

Expand All @@ -47,12 +46,9 @@ public static void verifyMetadataFieldNames(
HoodieCommitMetadata commitMetadata, List<String> expectedFieldNameList)
throws IOException {
String serializedCommitMetadata = commitMetadata.toJsonString();
Iterator<String> fieldNameIterator = JsonUtils.getObjectMapper()
.readTree(serializedCommitMetadata).fieldNames();
List<String> actualFieldNameList = new ArrayList<>();
while (fieldNameIterator.hasNext()) {
actualFieldNameList.add(fieldNameIterator.next());
}
List<String> actualFieldNameList = CollectionUtils.toStream(
JsonUtils.getObjectMapper().readTree(serializedCommitMetadata).fieldNames())
.collect(Collectors.toList());
assertEquals(
expectedFieldNameList.stream().sorted().collect(Collectors.toList()),
actualFieldNameList.stream().sorted().collect(Collectors.toList())
Expand Down

0 comments on commit 34f209d

Please sign in to comment.