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

handlebars.JavaJaxRS.resteasy.JodaLocalDateProvider.mustache Maven / Gradle / Ivy

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

import org.joda.time.LocalDate;
{{#jakarta}}
import jakarta.ws.rs.ext.ParamConverter;
import jakarta.ws.rs.ext.ParamConverterProvider;
import jakarta.ws.rs.ext.Provider;
import jakarta.ws.rs.WebApplicationException;
import javax.ws.rs.core.Response;
{{/jakarta}}
{{^jakarta}}
import javax.ws.rs.ext.ParamConverter;
import javax.ws.rs.ext.ParamConverterProvider;
import javax.ws.rs.ext.Provider;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Response;
{{/jakarta}}
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;


@Provider
public class JodaLocalDateProvider implements ParamConverterProvider {

    public static class JodaLocalDateConverter implements ParamConverter {

        public LocalDate fromString(String string) {
            try {
                LocalDate localDate = LocalDate.parse(string);
                return localDate;
            } catch (Exception e) {
                throw new WebApplicationException(Response.status(Response.Status.BAD_REQUEST).
                entity(string + " must be valid LocalDate").build());
            }
    }

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

    public  ParamConverter getConverter(Class type, Type type1, Annotation[] antns) {
        if (LocalDate.class.equals(type)) {
            return (ParamConverter) new JodaLocalDateConverter();
        }
        return null;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy