Skip to content

Commit

Permalink
Merge pull request #426 from focus-shift/424-jackson-mapping
Browse files Browse the repository at this point in the history
424 jackson mapping
  • Loading branch information
derTobsch authored Jan 13, 2024
2 parents 7785a9a + f2fccd1 commit 951b795
Show file tree
Hide file tree
Showing 12 changed files with 178 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
import de.focus_shift.jollyday.core.spi.YearCycle;

import java.time.Year;
import java.util.Collections;
import java.util.List;

import static java.util.stream.Collectors.toList;


public class JacksonIslamicHoliday implements IslamicHoliday {

Expand Down Expand Up @@ -59,6 +60,8 @@ public YearCycle cycle() {

@Override
public List<MovingCondition> conditions() {
return Collections.emptyList();
return islamicHoliday.getMovingCondition().stream()
.map(JacksonMovingCondition::new)
.collect(toList());
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package de.focus_shift.jollyday.jackson.mapping;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;

import java.util.ArrayList;
Expand All @@ -9,8 +10,13 @@
@JsonIgnoreProperties(ignoreUnknown = true)
public class Configuration {

@JacksonXmlElementWrapper(localName = "Holidays", useWrapping = false)
protected Holidays holidays;
@JacksonXmlElementWrapper(localName = "Sources", useWrapping = false)
protected Sources sources;
@JacksonXmlElementWrapper(localName = "SubConfigurations", useWrapping = false)
protected List<Configuration> subConfigurations;

@JacksonXmlProperty(localName = "hierarchy", isAttribute = true)
protected String hierarchy;
@JacksonXmlProperty(localName = "description", isAttribute = true)
Expand All @@ -36,6 +42,26 @@ public void setHolidays(Holidays value) {
this.holidays = value;
}

/**
* Gets the value of the sources' property.
*
* @return possible object is
* {@link Sources }
*/
public Sources getSources() {
return this.sources;
}

/**
* Sets the value of the sources property.
*
* @param sources allowed object is
* {@link Sources }
*/
public void setSources(Sources sources) {
this.sources = sources;
}

/**
* Gets the value of the subConfigurations property.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

public class FixedWeekdayBetweenFixed extends Holiday {


@JacksonXmlProperty(localName = "from")
protected Fixed from;
@JacksonXmlProperty(localName = "to")
protected Fixed to;

@JacksonXmlProperty(localName = "weekday", isAttribute = true)
protected Weekday weekday;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

public class FixedWeekdayRelativeToFixed extends Holiday {

@JacksonXmlProperty(localName = "day")
protected Fixed day;
@JacksonXmlProperty(localName = "which", isAttribute = true)
protected Which which;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;

public class IslamicHoliday extends Holiday {
public class IslamicHoliday extends MoveableHoliday {

@JacksonXmlProperty(localName = "type", isAttribute = true)
protected IslamicHolidayType type;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package de.focus_shift.jollyday.jackson.mapping;

import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;

import java.util.ArrayList;
import java.util.List;

public abstract class MoveableHoliday extends Holiday {

@JacksonXmlElementWrapper(localName = "MovingCondition", useWrapping = false)
protected List<MovingCondition> movingCondition;

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package de.focus_shift.jollyday.jackson.mapping;

import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;

public class RelativeToEasterSunday extends Holiday {

@JacksonXmlProperty(localName = "chronology", isAttribute = true)
protected ChronologyType chronology;
@JacksonXmlProperty(localName = "days", isAttribute = true)
protected int days;

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
package de.focus_shift.jollyday.jackson.mapping;

import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;

public class RelativeToFixed extends Holiday {

@JacksonXmlElementWrapper(localName = "Days", useWrapping = false)
protected Integer days;
@JacksonXmlElementWrapper(localName = "Weekday", useWrapping = false)
protected Weekday weekday;
@JacksonXmlElementWrapper(localName = "When", useWrapping = false)
protected When when;
@JacksonXmlElementWrapper(localName = "Date", useWrapping = false)
protected Fixed date;

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package de.focus_shift.jollyday.jackson.mapping;

import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;

public class RelativeToWeekdayInMonth extends Holiday {

@JacksonXmlElementWrapper(localName = "FixedWeekdayInMonth", useWrapping = false)
protected FixedWeekdayInMonth fixedWeekday;
@JacksonXmlProperty(localName = "weekday", isAttribute = true)
protected Weekday weekday;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package de.focus_shift.jollyday.jackson.mapping;

import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlText;


/**
* <p>Java class for Source complex type.
*
* <p>The following schema fragment specifies the expected content contained within this class.
*
* <pre>
* &lt;complexType name="Source"&gt;
* &lt;simpleContent&gt;
* &lt;extension base="&lt;http://www.w3.org/2001/XMLSchema&gt;string"&gt;
* &lt;attribute name="of" type="{http://www.w3.org/2001/XMLSchema}string" /&gt;
* &lt;/extension&gt;
* &lt;/simpleContent&gt;
* &lt;/complexType&gt;
* </pre>
*/
public class Source {

@JacksonXmlText
protected String value;
@JacksonXmlProperty(localName = "of", isAttribute = true)
protected String of;

/**
* Gets the value of the value property.
*
* @return possible object is
* {@link String }
*/
public String getValue() {
return value;
}

/**
* Sets the value of the value property.
*
* @param value allowed object is
* {@link String }
*/
public void setValue(String value) {
this.value = value;
}

/**
* Gets the value of the of property.
*
* @return possible object is
* {@link String }
*/
public String getOf() {
return of;
}

/**
* Sets the value of the of property.
*
* @param value allowed object is
* {@link String }
*/
public void setOf(String value) {
this.of = value;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package de.focus_shift.jollyday.jackson.mapping;

import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;

import java.util.ArrayList;
import java.util.List;


/**
* <p>Java class for Sources complex type.
*
* <p>The following schema fragment specifies the expected content contained within this class.
*
* <pre>
* &lt;complexType name="Sources"&gt;
* &lt;complexContent&gt;
* &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType"&gt;
* &lt;sequence&gt;
* &lt;element name="Source" type="{https://focus_shift.de/jollyday/schema/holiday}Source" maxOccurs="unbounded" minOccurs="0"/&gt;
* &lt;/sequence&gt;
* &lt;/restriction&gt;
* &lt;/complexContent&gt;
* &lt;/complexType&gt;
* </pre>
*/
public class Sources {

@JacksonXmlElementWrapper(localName = "Source", useWrapping = false)
protected List<Source> source;

/**
* Gets the value of the source property.
*
* <p>
* This accessor method returns a reference to the live list,
* not a snapshot. Therefore any modification you make to the
* returned list will be present inside the Jakarta XML Binding object.
* This is why there is not a <CODE>set</CODE> method for the source property.
*
* <p>
* For example, to add a new item, do as follows:
* <pre>
* getSource().add(newItem);
* </pre>
*
*
* <p>
* Objects of the following type(s) are allowed in the list
* {@link Source }
*/
public List<Source> getSource() {
if (source == null) {
source = new ArrayList<Source>();
}
return this.source;
}

}
2 changes: 1 addition & 1 deletion jollyday-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
</dependency>
<dependency>
<groupId>de.focus-shift</groupId>
<artifactId>jollyday-jaxb</artifactId>
<artifactId>jollyday-jackson</artifactId>
<version>${project.version}</version>
</dependency>

Expand Down

0 comments on commit 951b795

Please sign in to comment.