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

com.twingly.search.DateAdapter Maven / Gradle / Ivy

There is a newer version: 1.1.1
Show newest version
package com.twingly.search;

import javax.xml.bind.annotation.adapters.XmlAdapter;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Custom XMLAdapter that processes XML String date to java.util.Date in correct format.
 *
 * @see Constants#DATE_FORMAT
 */
public class DateAdapter extends XmlAdapter {
    private final SimpleDateFormat dateFormat = new SimpleDateFormat(Constants.DATE_FORMAT);

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

    /**
     * {@inheritDoc}
     */
    @Override
    public Date unmarshal(String v) throws Exception {
        if (v == null || "".equals(v.trim())) {
            return null;
        }
        return dateFormat.parse(v);
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy