From e55a140e7c39a9293c23c3f86c3ee36b42a65c71 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Sat, 28 Feb 2015 20:43:44 +0100 Subject: [PATCH] [New] added Iso8601DateAdapter for JAXB (un)marshalling of ISO8601 dates --- .../strolch/model/xml/Iso8601DateAdapter.java | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 li.strolch.model/src/main/java/li/strolch/model/xml/Iso8601DateAdapter.java diff --git a/li.strolch.model/src/main/java/li/strolch/model/xml/Iso8601DateAdapter.java b/li.strolch.model/src/main/java/li/strolch/model/xml/Iso8601DateAdapter.java new file mode 100644 index 000000000..aacb49879 --- /dev/null +++ b/li.strolch.model/src/main/java/li/strolch/model/xml/Iso8601DateAdapter.java @@ -0,0 +1,25 @@ +package li.strolch.model.xml; + +import java.util.Date; + +import javax.xml.bind.annotation.adapters.XmlAdapter; + +import ch.eitchnet.utils.helper.StringHelper; +import ch.eitchnet.utils.iso8601.ISO8601FormatFactory; + +public class Iso8601DateAdapter extends XmlAdapter { + + @Override + public Date unmarshal(String value) throws Exception { + if (StringHelper.isEmpty(value)) + return null; + return ISO8601FormatFactory.getInstance().getDateFormat().parse(value); + } + + @Override + public String marshal(Date value) throws Exception { + if (value == null) + return StringHelper.EMPTY; + return ISO8601FormatFactory.getInstance().formatDate(value); + } +} \ No newline at end of file