handlebars.JavaJaxRS.libraries.jersey2.OffsetDateTimeProvider.mustache Maven / Gradle / Ivy
package {{apiPackage}};
{{#jakarta}}
import jakarta.ws.rs.ext.ParamConverter;
import jakarta.ws.rs.ext.ParamConverterProvider;
import jakarta.ws.rs.ext.Provider;
{{/jakarta}}
{{^jakarta}}
import javax.ws.rs.ext.ParamConverter;
import javax.ws.rs.ext.ParamConverterProvider;
import javax.ws.rs.ext.Provider;
{{/jakarta}}
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
import java.time.OffsetDateTime;
@Provider
public class OffsetDateTimeProvider implements ParamConverterProvider {
public ParamConverter getConverter(Class clazz, Type type, Annotation[] annotations) {
if (clazz.getName().equals(OffsetDateTime.class.getName())) {
return new ParamConverter() {
@SuppressWarnings("unchecked")
public T fromString(String value) {
return value != null ? (T) OffsetDateTime.parse(value) : null;
}
public String toString(T bean) {
return bean != null ? bean.toString() : "";
}
};
}
return null;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy