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

se.fortnox.reactivewizard.jaxrs.params.deserializing.DateDeserializer Maven / Gradle / Ivy

There is a newer version: 24.6.0
Show newest version
package se.fortnox.reactivewizard.jaxrs.params.deserializing;

import jakarta.inject.Provider;

import java.text.DateFormat;
import java.util.Date;

/**
 * Deserializes dates.
 */
public class DateDeserializer implements Deserializer {
    private Provider dateFormatProvider;

    public DateDeserializer(Provider dateFormatProvider) {
        this.dateFormatProvider = dateFormatProvider;
    }

    @Override
    public Date deserialize(String value) throws DeserializerException {
        if (value == null) {
            return null;
        }
        try {
            return new Date(Long.parseLong(value));
        } catch (NumberFormatException e) {
            try {
                return dateFormatProvider.get().parse(value);
            } catch (Exception parseException) {
                throw new DeserializerException("invalid.date");
            }
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy