Skip to content

Commit

Permalink
Add LocalDateXmlAdapter.java
Browse files Browse the repository at this point in the history
  • Loading branch information
NghiNg committed Jan 4, 2024
1 parent 31b84ea commit 9255eda
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package no.digipost.api.datatypes.marshalling;

import jakarta.xml.bind.annotation.adapters.XmlAdapter;

import java.time.LocalDate;
public class LocalDateXmlAdapter extends XmlAdapter<String, LocalDate> {
@Override
public String marshal(LocalDate v) {
if (v == null) {
return null;
}
return v.toString();
}

@Override
public LocalDate unmarshal(final String s) {
if (s == null) {
return null;
}
return LocalDate.parse(s);
}

}
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
@XmlSchema(namespace = DIGIPOST_DATATYPES_NAMESPACE, elementFormDefault = jakarta.xml.bind.annotation.XmlNsForm.QUALIFIED)
@XmlAccessorType(XmlAccessType.FIELD)
@XmlJavaTypeAdapter(ZonedDateTimeXmlAdapter.class)
@XmlJavaTypeAdapters({
@XmlJavaTypeAdapter(ZonedDateTimeXmlAdapter.class),
@XmlJavaTypeAdapter(LocalDateXmlAdapter.class)
})
@DataTypePackage
package no.digipost.api.datatypes.types.invoice;

import jakarta.xml.bind.annotation.XmlAccessType;
import jakarta.xml.bind.annotation.XmlAccessorType;
import jakarta.xml.bind.annotation.XmlSchema;
import jakarta.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import jakarta.xml.bind.annotation.adapters.XmlJavaTypeAdapters;
import no.digipost.api.datatypes.documentation.DataTypePackage;
import no.digipost.api.datatypes.marshalling.LocalDateXmlAdapter;
import no.digipost.api.datatypes.marshalling.ZonedDateTimeXmlAdapter;

import static no.digipost.api.datatypes.marshalling.DataTypesJAXBContext.DIGIPOST_DATATYPES_NAMESPACE;

0 comments on commit 9255eda

Please sign in to comment.