se.fortnox.reactivewizard.jaxrs.params.annotated.PathParamResolver Maven / Gradle / Ivy
package se.fortnox.reactivewizard.jaxrs.params.annotated;
import com.fasterxml.jackson.core.type.TypeReference;
import se.fortnox.reactivewizard.jaxrs.JaxRsRequest;
import se.fortnox.reactivewizard.jaxrs.params.ParamResolver;
import se.fortnox.reactivewizard.jaxrs.params.deserializing.Deserializer;
import se.fortnox.reactivewizard.jaxrs.params.deserializing.DeserializerFactory;
import javax.ws.rs.PathParam;
import java.lang.annotation.Annotation;
/**
* Bind a path parameter to a method parameter.
*/
class PathParamResolver extends AnnotatedParamResolver {
public PathParamResolver(Deserializer deserializer, Annotation pathParamAnnotation, String defaultValue) {
super(deserializer, ((PathParam)pathParamAnnotation).value(), defaultValue);
if (defaultValue != null) {
throw new UnsupportedOperationException("@DefaultValue is not implemented for @PathParam");
}
}
@Override
protected String getValue(JaxRsRequest request) {
return request.getPathParam(parameterName, getDefaultValue());
}
public static class Factory implements AnnotatedParamResolverFactory {
private final DeserializerFactory deserializerFactory;
public Factory(DeserializerFactory deserializerFactory) {
this.deserializerFactory = deserializerFactory;
}
@Override
public ParamResolver create(TypeReference paramType, Annotation annotation, String defaultValue) {
return new PathParamResolver<>(deserializerFactory.getParamDeserializer(paramType), annotation, defaultValue);
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy