[New] added Iso8601DateAdapter for JAXB (un)marshalling of ISO8601 dates

This commit is contained in:
Robert von Burg 2015-02-28 20:43:44 +01:00
parent a46d5364e4
commit e55a140e7c
1 changed files with 25 additions and 0 deletions

View File

@ -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<String, Date> {
@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);
}
}