Skip to content

Commit b7486cb

Browse files
committed
Refactor JSON handling and update Lombok config
Replaces use of Iterator with properties() for JsonNode traversal in DumAemCommonsUtils, improving code clarity. Updates ObjectMapper configuration to use setDefaultPropertyInclusion for JSON export. Adds Lombok annotation processor to Maven compiler plugin configuration for better annotation processing support.
1 parent 632ec27 commit b7486cb

File tree

3 files changed

+16
-11
lines changed

3 files changed

+16
-11
lines changed

aem-commons/src/main/java/com/viglet/dumont/connector/aem/commons/DumAemCommonsUtils.java

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
import java.util.Collections;
3434
import java.util.Date;
3535
import java.util.HashSet;
36-
import java.util.Iterator;
3736
import java.util.List;
3837
import java.util.Locale;
3938
import java.util.Map;
@@ -81,7 +80,7 @@
8180
public class DumAemCommonsUtils {
8281

8382
private static final Cache<String, Optional<String>> responseBodyCache = Caffeine.newBuilder().maximumSize(1000)
84-
.expireAfterWrite(Duration.ofMinutes(5)).build();
83+
.expireAfterWrite(Objects.requireNonNull(Duration.ofMinutes(5))).build();
8584

8685
private DumAemCommonsUtils() {
8786
throw new IllegalStateException("Utility class");
@@ -108,11 +107,9 @@ private static Set<String> getContentValues(JsonNode node) {
108107

109108
private static void extractContentValues(JsonNode node, Set<String> results) {
110109
if (node.isObject()) {
111-
Iterator<Map.Entry<String, JsonNode>> fields = node.fields();
112-
while (fields.hasNext()) {
113-
Map.Entry<String, JsonNode> entry = fields.next();
114-
extractContentValues(entry.getValue(), results);
115-
}
110+
node.properties().forEach(property -> {
111+
extractContentValues(property.getValue(), results);
112+
});
116113
} else if (node.isArray()) {
117114
for (JsonNode item : node) {
118115
extractContentValues(item, results);
@@ -336,10 +333,10 @@ public static <T> Optional<T> getResponseBody(String url,
336333
}
337334
}
338335

339-
public static @NotNull Optional<String> fetchResponseBodyWithoutCache(String url,
336+
public static @NotNull Optional<String> fetchResponseBodyWithoutCache(@NotNull String url,
340337
DumAemConfiguration dumAemSourceContext) throws IOException {
341-
String escapedUrl = UrlEscapers.urlFragmentEscaper().escape(url);
342-
URI normalizedUri = URI.create(Objects.requireNonNull(escapedUrl, "URL cannot be null")).normalize();
338+
String escapedUrl = Objects.requireNonNull(UrlEscapers.urlFragmentEscaper().escape(url));
339+
URI normalizedUri = URI.create(escapedUrl).normalize();
343340

344341
try (CloseableHttpClient httpClient = createHttpClient(dumAemSourceContext)) {
345342
HttpGet request = new HttpGet(normalizedUri);

aem/aem-plugin/src/main/java/com/viglet/dumont/connector/plugin/aem/export/DumAemExchangeProcess.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ public StreamingResponseBody exportObject(HttpServletResponse response) {
127127
log.error(e.getMessage(), e);
128128
}
129129
// Object to JSON in file
130-
ObjectMapper mapper = new ObjectMapper().setSerializationInclusion(JsonInclude.Include.NON_NULL);
130+
ObjectMapper mapper = new ObjectMapper().setDefaultPropertyInclusion(JsonInclude.Include.NON_NULL);
131131
try {
132132
mapper.writerWithDefaultPrettyPrinter().writeValue(exportFile,
133133
new DumAemExchange(dumAemSources.stream()

pom.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,15 @@
145145
<arg>-Xlint:unchecked</arg>
146146
<arg>-Xlint:deprecation</arg>
147147
</compilerArgs>
148+
<annotationProcessorPaths>
149+
<path>
150+
<groupId>org.projectlombok</groupId>
151+
<artifactId>lombok</artifactId>
152+
<version>1.18.42</version>
153+
</path>
154+
</annotationProcessorPaths>
148155
</configuration>
156+
149157
</plugin>
150158
</plugins>
151159
</pluginManagement>

0 commit comments

Comments
 (0)