se.fortnox.reactivewizard.jaxrs.params.deserializing.DateDeserializer Maven / Gradle / Ivy
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