handlebars.JavaSpring.LocalDateConverter.mustache Maven / Gradle / Ivy
package {{configPackage}};
import org.springframework.core.convert.converter.Converter;
{{^isJava8or11}}
import org.threeten.bp.LocalDate;
import org.threeten.bp.format.DateTimeFormatter;
{{/isJava8or11}}
{{#isJava8or11}}
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
{{/isJava8or11}}
public class LocalDateConverter implements Converter {
private final DateTimeFormatter formatter;
public LocalDateConverter(String dateFormat) {
this.formatter = DateTimeFormatter.ofPattern(dateFormat);
}
@Override
public LocalDate convert(String source) {
if(source == null || source.isEmpty()) {
return null;
}
return LocalDate.parse(source, this.formatter);
}
}