Repository: focus-shift/jollyday
Pull request #709 (2024-12-26 11:13:07)

Rename xmlUtils to (Jackson/Jaxb)XMLMapper
<!--

Thanks for contributing.
Please review the following notes before submitting you pull request.

Please look for other issues or pull requests which already work on this topic. Is somebody already on it? Do you need to synchronize?

# Security Vulnerabilities

🛑 STOP! 🛑 If your contribution fixes a security vulnerability, please do not submit it.
Instead, please write an E-Mail to to one of the maintainer with all the information
to recreate the security vulnerability.

# Describing Your Changes

If, having reviewed the notes above, you're ready to submit your pull request, please
provide a brief description of the proposed changes.

If they:
 🐞 fix a bug, please describe the broken behaviour and how the changes fix it.
    Please label with 'type: bug' and 'status: new'
    
 🎁 make an enhancement, please describe the new functionality and why you believe it's useful.
    Please label with 'type: enhancement' and 'status: new'
 
If your pull request relates to any existing issues,
please reference them by using the issue number prefixed with #.

-->



Patch:
diff --git a/jollyday-jackson/src/main/java/de/focus_shift/jollyday/jackson/JacksonConfigurationService.java b/jollyday-jackson/src/main/java/de/focus_shift/jollyday/jackson/JacksonConfigurationService.java
index 442c1d62..09eeda5a 100644
--- a/jollyday-jackson/src/main/java/de/focus_shift/jollyday/jackson/JacksonConfigurationService.java
+++ b/jollyday-jackson/src/main/java/de/focus_shift/jollyday/jackson/JacksonConfigurationService.java
@@ -12,7 +12,7 @@ import java.net.URL;
  */
 public class JacksonConfigurationService implements ConfigurationService {
 
-  private static final XMLUtil xmlUtil = new XMLUtil();
+  private static final JacksonXMLMapper xmlUtil = new JacksonXMLMapper();
 
   /**
    * {@inheritDoc}
diff --git a/jollyday-jackson/src/main/java/de/focus_shift/jollyday/jackson/XMLUtil.java b/jollyday-jackson/src/main/java/de/focus_shift/jollyday/jackson/JacksonXMLMapper.java
similarity index 83%
rename from jollyday-jackson/src/main/java/de/focus_shift/jollyday/jackson/XMLUtil.java
rename to jollyday-jackson/src/main/java/de/focus_shift/jollyday/jackson/JacksonXMLMapper.java
index 35ac0a67..a73e6999 100644
--- a/jollyday-jackson/src/main/java/de/focus_shift/jollyday/jackson/XMLUtil.java
+++ b/jollyday-jackson/src/main/java/de/focus_shift/jollyday/jackson/JacksonXMLMapper.java
@@ -1,12 +1,13 @@
 package de.focus_shift.jollyday.jackson;
 
-import com.fasterxml.jackson.databind.PropertyNamingStrategies;
 import com.fasterxml.jackson.dataformat.xml.XmlMapper;
 import de.focus_shift.jollyday.jackson.mapping.Configuration;
 
 import java.io.InputStream;
 
-public class XMLUtil {
+import static com.fasterxml.jackson.databind.PropertyNamingStrategies.UPPER_CAMEL_CASE;
+
+public class JacksonXMLMapper {
 
   private static final XmlMapper mapper = new JacksonMapperCreator().create();
 
@@ -28,7 +29,7 @@ public class XMLUtil {
   private static class JacksonMapperCreator {
     private XmlMapper create() {
       final XmlMapper mapper = new XmlMapper();
-      mapper.setPropertyNamingStrategy(PropertyNamingStrategies.UPPER_CAMEL_CASE);
+      mapper.setPropertyNamingStrategy(UPPER_CAMEL_CASE);
       return mapper;
     }
   }
diff --git a/jollyday-jaxb/src/main/java/de/focus_shift/jollyday/jaxb/JaxbConfigurationService.java b/jollyday-jaxb/src/main/java/de/focus_shift/jollyday/jaxb/JaxbConfigurationService.java
index 23211299..2eb6043e 100644
--- a/jollyday-jaxb/src/main/java/de/focus_shift/jollyday/jaxb/JaxbConfigurationService.java
+++ b/jollyday-jaxb/src/main/java/de/focus_shift/jollyday/jaxb/JaxbConfigurationService.java
@@ -12,7 +12,7 @@ import java.net.URL;
  */
 public class JaxbConfigurationService implements ConfigurationService {
 
-  private static final XMLUtil xmlUtil = new XMLUtil();
+  private static final JaxbXMLMapper xmlUtil = new JaxbXMLMapper();
 
   /**
    * {@inheritDoc}
diff --git a/jollyday-jaxb/src/main/java/de/focus_shift/jollyday/jaxb/XMLUtil.java b/jollyday-jaxb/src/main/java/de/focus_shift/jollyday/jaxb/JaxbXMLMapper.java
similarity index 87%
rename from jollyday-jaxb/src/main/java/de/focus_shift/jollyday/jaxb/XMLUtil.java
rename to jollyday-jaxb/src/main/java/de/focus_shift/jollyday/jaxb/JaxbXMLMapper.java
index bc6b588a..560e23d7 100644
--- a/jollyday-jaxb/src/main/java/de/focus_shift/jollyday/jaxb/XMLUtil.java
+++ b/jollyday-jaxb/src/main/java/de/focus_shift/jollyday/jaxb/JaxbXMLMapper.java
@@ -12,14 +12,14 @@ import org.slf4j.LoggerFactory;
 
 import java.io.InputStream;
 
-public class XMLUtil {
+public class JaxbXMLMapper {
 
   /**
    * the package name to search for the generated java classes.
    */
   private static final String PACKAGE = "de.focus_shift.jollyday.jaxb.mapping";
 
-  private static final Logger LOG = LoggerFactory.getLogger(XMLUtil.class);
+  private static final Logger LOG = LoggerFactory.getLogger(JaxbXMLMapper.class);
 
   private static final JAXBContext jaxbContext = new JAXBContextCreator().create();
 
@@ -52,14 +52,14 @@ public class XMLUtil {
     private static JAXBContext createJAXBContext() {
       JAXBContext ctx = null;
       try {
-        ctx = JAXBContext.newInstance(XMLUtil.PACKAGE, ClassLoadingUtil.getClassloader());
+        ctx = JAXBContext.newInstance(JaxbXMLMapper.PACKAGE, ClassLoadingUtil.getClassloader());
       } catch (JAXBException e) {
         LOG.warn("Could not create JAXB context using the current classloader from ClassLoadingUtil. Falling back to ObjectFactory class classloader.");
       }
 
       if (ctx == null) {
         try {
-          ctx = JAXBContext.newInstance(XMLUtil.PACKAGE, ObjectFactory.class.getClassLoader());
+          ctx = JAXBContext.newInstance(JaxbXMLMapper.PACKAGE, ObjectFactory.class.getClassLoader());
         } catch (JAXBException exception) {
           throw new IllegalStateException("Could not create JAXB context using ObjectFactory classloader.", exception);
         }


Test patch:
diff --git a/jollyday-jackson/src/test/java/de/focus_shift/jollyday/jackson/test/XMLUtilTest.java b/jollyday-jackson/src/test/java/de/focus_shift/jollyday/jackson/test/XMLUtilTest.java
index 0f1643fd..f01d365d 100644
--- a/jollyday-jackson/src/test/java/de/focus_shift/jollyday/jackson/test/XMLUtilTest.java
+++ b/jollyday-jackson/src/test/java/de/focus_shift/jollyday/jackson/test/XMLUtilTest.java
@@ -1,6 +1,6 @@
 package de.focus_shift.jollyday.jackson.test;
 
-import de.focus_shift.jollyday.jackson.XMLUtil;
+import de.focus_shift.jollyday.jackson.JacksonXMLMapper;
 import de.focus_shift.jollyday.jackson.mapping.Configuration;
 import org.junit.jupiter.params.ParameterizedTest;
 import org.junit.jupiter.params.provider.ValueSource;
@@ -14,7 +14,7 @@ class XMLUtilTest {
   @ParameterizedTest
   @ValueSource(strings = {"Holidays_at.xml", "Holidays_de.xml", "Holidays_gb.xml", "Holidays_ua.xml", "Holidays_tr.xml", "Holidays_za.xml"})
   void unmarshalRealResource(String holidayFileName) {
-    final XMLUtil sut = new XMLUtil();
+    final JacksonXMLMapper sut = new JacksonXMLMapper();
     final InputStream inputStream = getClass().getClassLoader().getResourceAsStream("holidays/" + holidayFileName);
     final Configuration configuration = sut.unmarshallConfiguration(inputStream);
     assertThat(configuration.getHolidays()).isNotNull();
diff --git a/jollyday-jaxb/src/test/java/de/focus_shift/jollyday/jaxb/test/XMLUtilTest.java b/jollyday-jaxb/src/test/java/de/focus_shift/jollyday/jaxb/test/XMLUtilTest.java
index 1bc58da5..f2a5c1cd 100644
--- a/jollyday-jaxb/src/test/java/de/focus_shift/jollyday/jaxb/test/XMLUtilTest.java
+++ b/jollyday-jaxb/src/test/java/de/focus_shift/jollyday/jaxb/test/XMLUtilTest.java
@@ -1,6 +1,6 @@
 package de.focus_shift.jollyday.jaxb.test;
 
-import de.focus_shift.jollyday.jaxb.XMLUtil;
+import de.focus_shift.jollyday.jaxb.JaxbXMLMapper;
 import de.focus_shift.jollyday.jaxb.mapping.Configuration;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.params.ParameterizedTest;
@@ -13,7 +13,7 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy;
 
 class XMLUtilTest {
 
-  private final XMLUtil sut = new XMLUtil();
+  private final JaxbXMLMapper sut = new JaxbXMLMapper();
 
   @Test
   void testUnmarshallConfigurationNullCheck() {