All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.fedy2.weather.binding.adapter.DateAdapter Maven / Gradle / Ivy

There is a newer version: 2.0.2
Show newest version
/**
 * 
 */
package com.github.fedy2.weather.binding.adapter;

import java.text.SimpleDateFormat;
import java.util.Date;

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

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author "Federico De Faveri [email protected]"
 *
 */
public class DateAdapter extends XmlAdapter {

	protected Logger logger = LoggerFactory.getLogger(DateAdapter.class);

	protected SimpleDateFormat dateFormat = new SimpleDateFormat("d MMM yyyy");

	/**
	 * {@inheritDoc}
	 */
	@Override
	public String marshal(Date v) throws Exception {
		return dateFormat.format(v);
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public Date unmarshal(String v) throws Exception {

		try {
			return dateFormat.parse(v);
		} catch(Exception e) {
			logger.warn("Unknow date format \"{}\"",v);
			return null;
		}
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy