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

JavaJaxRS.libraries.jersey2.LocalDateProvider.mustache Maven / Gradle / Ivy

There is a newer version: 7.9.0
Show newest version
package {{apiPackage}};

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

@Provider
public class LocalDateProvider implements ParamConverterProvider {

    public  ParamConverter getConverter(Class clazz, Type type, Annotation[] annotations) {
        if (clazz.getName().equals(LocalDate.class.getName())) {
            return new ParamConverter() {
                @SuppressWarnings("unchecked")
                public T fromString(String value) {
                    return value!=null ? (T) LocalDate.parse(value) : null;
                }

                public String toString(T bean) {
                    return bean!=null ? bean.toString() : "";
                }
            };
        }
        return null;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy