Example usage for org.springframework.core MethodParameter getParameterAnnotation

List of usage examples for org.springframework.core MethodParameter getParameterAnnotation

Introduction

In this page you can find the example usage for org.springframework.core MethodParameter getParameterAnnotation.

Prototype

@SuppressWarnings("unchecked")
@Nullable
public <A extends Annotation> A getParameterAnnotation(Class<A> annotationType) 

Source Link

Document

Return the parameter annotation of the given type, if available.

Usage

From source file:capital.scalable.restdocs.payload.JacksonRequestFieldSnippet.java

private boolean isRequestBody(MethodParameter param) {
    return param.getParameterAnnotation(RequestBody.class) != null;
}

From source file:fi.helsinki.opintoni.web.arguments.StudentNumberArgumentResolver.java

@Override
public boolean supportsParameter(MethodParameter parameter) {
    if (parameter.getParameterAnnotation(StudentNumber.class) == null) {
        return false;
    }//from  ww  w  .  j a va 2  s  .  c om

    if (parameter.getParameterType() != String.class) {
        throw new ForbiddenException("Student number must be of type String");
    }

    return true;
}

From source file:fi.helsinki.opintoni.web.arguments.TeacherNumberArgumentResolver.java

@Override
public boolean supportsParameter(MethodParameter parameter) {
    if (parameter.getParameterAnnotation(TeacherNumber.class) == null) {
        return false;
    }//from  w  ww .j  av  a2  s.  com

    if (parameter.getParameterType() != String.class) {
        throw new ForbiddenException("Teacher number must be of type String");
    }

    return true;
}

From source file:fi.helsinki.opintoni.web.arguments.UsernameArgumentResolver.java

@Override
public boolean supportsParameter(MethodParameter parameter) {
    if (parameter.getParameterAnnotation(Username.class) == null) {
        return false;
    }//from  w ww  .jav a2  s  .  c  o  m

    if (parameter.getParameterType() != String.class) {
        throw new ForbiddenException("Username must be of type String");
    }

    return true;
}

From source file:fi.helsinki.opintoni.web.arguments.UserIdArgumentResolver.java

@Override
public boolean supportsParameter(MethodParameter parameter) {
    if (parameter.getParameterAnnotation(UserId.class) == null) {
        return false;
    }//from w w w  .  java  2  s.  c o  m

    if (parameter.getParameterType() != Long.class) {
        throw new ForbiddenException("User id must be of type Long");
    }

    return true;
}

From source file:com.miserablemind.butter.resolvers.user.ActiveUserMethodArgumentResolver.java

/**
 * Checks if parameter is of the right type and has correct annotation (@ActiveUser in this case)
 *
 * @param methodParameter parameter being resolved.
 * @return {@code true} if parameter is supported.
 *///from   w  w w  .ja v a2  s  . c  o m
@Override
public boolean supportsParameter(MethodParameter methodParameter) {
    return methodParameter.getParameterAnnotation(ActiveUser.class) != null
            && methodParameter.getParameterType().equals(AppUser.class);
}

From source file:org.ngrinder.infra.spring.RemainedPathMethodArgumentResolver.java

@Override
public boolean supportsParameter(MethodParameter parameter) {
    return parameter.getParameterAnnotation(RemainedPath.class) != null;
}

From source file:springfox.documentation.swagger1.readers.parameter.ParameterNameReader.java

@VisibleForTesting
Optional<ApiParam> apiParam(MethodParameter methodParameter) {
    return fromNullable(methodParameter.getParameterAnnotation(ApiParam.class))
            .or(annotations.fromHierarchy(methodParameter, ApiParam.class));
}

From source file:springfox.documentation.swagger.readers.parameter.ParameterDescriptionReader.java

@Override
public void apply(ParameterContext context) {
    MethodParameter methodParameter = context.methodParameter();
    ApiParam apiParam = methodParameter.getParameterAnnotation(ApiParam.class);
    if (null != apiParam && hasText(apiParam.value())) {
        context.parameterBuilder().description(apiParam.value());
    }/*from   w  w w.ja  v  a2 s  . co  m*/
}

From source file:springfox.documentation.swagger.readers.parameter.ParameterAccessReader.java

@Override
public void apply(ParameterContext context) {
    MethodParameter methodParameter = context.methodParameter();
    ApiParam apiParam = methodParameter.getParameterAnnotation(ApiParam.class);
    if (apiParam != null && !isNullOrEmpty(apiParam.access())) {
        String access = apiParam.access();
        context.parameterBuilder().parameterAccess(access);
    }/*from  w ww. ja  va 2 s.c  o  m*/
}