package {{apiPackage}};

import java.time.LocalDate;
import javax.ws.rs.ext.ParamConverter;
import javax.ws.rs.ext.ParamConverterProvider;
import javax.ws.rs.ext.Provider;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;

@Provider
public class LocalDateProvider implements ParamConverterProvider {

    public static class LocalDateConverter implements ParamConverter<LocalDate> {

        @Override
        public LocalDate fromString(String string) {
            LocalDate localDate = LocalDate.parse(string);
            return localDate;
        }

        @Override
        public String toString(LocalDate t) {
            return t.toString();
        }
    }

    @Override
    public <T> ParamConverter<T> getConverter(Class<T> type, Type type1, Annotation[] antns) {
        if (LocalDate.class.equals(type)) {
            return (ParamConverter<T>) new LocalDateConverter();
        }
        return null;
    }
}