Created
November 11, 2020 00:51
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.lang.annotation.Annotation; | |
import java.lang.reflect.Type; | |
import java.time.LocalDate; | |
import javax.ws.rs.ext.ParamConverter; | |
import javax.ws.rs.ext.ParamConverterProvider; | |
import javax.ws.rs.ext.Provider; | |
@Provider | |
public class LocalDateParamConverterProvider implements ParamConverterProvider { | |
@SuppressWarnings("unchecked") | |
@Override | |
public <T> ParamConverter<T> getConverter(Class<T> rawType, Type genericType, Annotation[] annotations) { | |
if (rawType.isAssignableFrom(LocalDate.class)) { | |
return (ParamConverter<T>) new LocalDateParamConverter(); | |
} | |
return null; | |
} | |
public static class LocalDateParamConverter implements ParamConverter<LocalDate> { | |
public static final String DATE_PATTERN = "yyyyMMdd"; | |
@Override | |
public LocalDate fromString(String param) { | |
return LocalDate.parse(param); | |
} | |
@Override | |
public String toString(LocalDate date) { | |
return date.toString(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment