Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename xmlUtils to (Jackson/Jaxb)XMLMapper #709

Merged
merged 1 commit into from
Dec 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*/
public class JacksonConfigurationService implements ConfigurationService {

private static final XMLUtil xmlUtil = new XMLUtil();
private static final JacksonXMLMapper xmlUtil = new JacksonXMLMapper();

/**
* {@inheritDoc}
Expand Down
Original file line number Diff line number Diff line change
@@ -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();

Expand All @@ -28,7 +29,7 @@ public Configuration unmarshallConfiguration(InputStream stream) {
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;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*/
public class JaxbConfigurationService implements ConfigurationService {

private static final XMLUtil xmlUtil = new XMLUtil();
private static final JaxbXMLMapper xmlUtil = new JaxbXMLMapper();

/**
* {@inheritDoc}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@

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();

Expand Down Expand Up @@ -52,14 +52,14 @@ private JAXBContext create() {
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);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -13,7 +13,7 @@

class XMLUtilTest {

private final XMLUtil sut = new XMLUtil();
private final JaxbXMLMapper sut = new JaxbXMLMapper();

@Test
void testUnmarshallConfigurationNullCheck() {
Expand Down
Loading