Java Code Examples for org.springframework.core.MethodParameter#getParameterAnnotation()
The following examples show how to use
org.springframework.core.MethodParameter#getParameterAnnotation() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MappingJackson2MessageConverter.java From spring-analysis-note with MIT License | 6 votes |
/** * Determine a Jackson serialization view based on the given conversion hint. * @param conversionHint the conversion hint Object as passed into the * converter for the current conversion attempt * @return the serialization view class, or {@code null} if none * @since 4.2 */ @Nullable protected Class<?> getSerializationView(@Nullable Object conversionHint) { if (conversionHint instanceof MethodParameter) { MethodParameter param = (MethodParameter) conversionHint; JsonView annotation = (param.getParameterIndex() >= 0 ? param.getParameterAnnotation(JsonView.class) : param.getMethodAnnotation(JsonView.class)); if (annotation != null) { return extractViewClass(annotation, conversionHint); } } else if (conversionHint instanceof JsonView) { return extractViewClass((JsonView) conversionHint, conversionHint); } else if (conversionHint instanceof Class) { return (Class<?>) conversionHint; } // No JSON view specified... return null; }
Example 2
Source File: MappingJackson2MessageConverter.java From spring-analysis-note with MIT License | 6 votes |
/** * Determine a Jackson serialization view based on the given conversion hint. * @param conversionHint the conversion hint Object as passed into the * converter for the current conversion attempt * @return the serialization view class, or {@code null} if none */ @Nullable protected Class<?> getSerializationView(@Nullable Object conversionHint) { if (conversionHint instanceof MethodParameter) { MethodParameter methodParam = (MethodParameter) conversionHint; JsonView annotation = methodParam.getParameterAnnotation(JsonView.class); if (annotation == null) { annotation = methodParam.getMethodAnnotation(JsonView.class); if (annotation == null) { return null; } } return extractViewClass(annotation, conversionHint); } else if (conversionHint instanceof JsonView) { return extractViewClass((JsonView) conversionHint, conversionHint); } else if (conversionHint instanceof Class) { return (Class<?>) conversionHint; } else { return null; } }
Example 3
Source File: MvcAnnotationPredicates.java From spring-analysis-note with MIT License | 5 votes |
@Override public boolean test(MethodParameter parameter) { RequestAttribute annotation = parameter.getParameterAnnotation(RequestAttribute.class); return annotation != null && (this.name == null || annotation.name().equals(this.name)) && annotation.required() == this.required; }
Example 4
Source File: JsonViewRequestBodyAdvice.java From java-technology-stack with MIT License | 5 votes |
@Override public boolean supports(MethodParameter methodParameter, Type targetType, Class<? extends HttpMessageConverter<?>> converterType) { return (AbstractJackson2HttpMessageConverter.class.isAssignableFrom(converterType) && methodParameter.getParameterAnnotation(JsonView.class) != null); }
Example 5
Source File: MvcAnnotationPredicates.java From java-technology-stack with MIT License | 5 votes |
@Override public boolean test(MethodParameter parameter) { RequestPart annotation = parameter.getParameterAnnotation(RequestPart.class); return annotation != null && (this.name == null || annotation.name().equals(this.name)) && annotation.required() == this.required; }
Example 6
Source File: RequestParamMapMethodArgumentResolver.java From lams with GNU General Public License v2.0 | 5 votes |
@Override public boolean supportsParameter(MethodParameter parameter) { RequestParam requestParam = parameter.getParameterAnnotation(RequestParam.class); if (requestParam != null) { if (Map.class.isAssignableFrom(parameter.getParameterType())) { return !StringUtils.hasText(requestParam.name()); } } return false; }
Example 7
Source File: MethodParameterUtil.java From specification-arg-resolver with Apache License 2.0 | 5 votes |
public static <A extends Annotation> A getAnnotation(Class<A> annotationType, MethodParameter parameter) { A annotation = parameter.getParameterAnnotation(annotationType); if (annotation == null) { annotation = parameter.getParameterType().getAnnotation(annotationType); } return annotation; }
Example 8
Source File: RequestBodyMethodArgumentResolver.java From spring-analysis-note with MIT License | 5 votes |
@Override public Mono<Object> resolveArgument( MethodParameter param, BindingContext bindingContext, ServerWebExchange exchange) { RequestBody ann = param.getParameterAnnotation(RequestBody.class); Assert.state(ann != null, "No RequestBody annotation"); return readBody(param, ann.required(), bindingContext, exchange); }
Example 9
Source File: PathVariableMethodArgumentResolver.java From spring-analysis-note with MIT License | 5 votes |
@Override public void contributeMethodArgument(MethodParameter parameter, Object value, UriComponentsBuilder builder, Map<String, Object> uriVariables, ConversionService conversionService) { if (Map.class.isAssignableFrom(parameter.nestedIfOptional().getNestedParameterType())) { return; } PathVariable ann = parameter.getParameterAnnotation(PathVariable.class); String name = (ann != null && StringUtils.hasLength(ann.value()) ? ann.value() : parameter.getParameterName()); String formatted = formatUriValue(conversionService, new TypeDescriptor(parameter.nestedIfOptional()), value); uriVariables.put(name, formatted); }
Example 10
Source File: AbstractCookieValueMethodArgumentResolver.java From spring4-understanding with Apache License 2.0 | 4 votes |
@Override protected NamedValueInfo createNamedValueInfo(MethodParameter parameter) { CookieValue annotation = parameter.getParameterAnnotation(CookieValue.class); return new CookieValueNamedValueInfo(annotation); }
Example 11
Source File: UserDetailsArgumentResolver.java From slackspace-angular-spring-keycloak with Apache License 2.0 | 4 votes |
@Override public boolean supportsParameter(MethodParameter methodParameter) { return methodParameter.getParameterAnnotation(CurrentUser.class) != null && methodParameter.getParameterType().equals(UserDetails.class); }
Example 12
Source File: ParamHandler.java From api-document with GNU General Public License v3.0 | 4 votes |
private static boolean paramHasMust(MethodParameter parameter) { RequestParam requestParam = parameter.getParameterAnnotation(RequestParam.class); if (Tools.isNotBlank(requestParam) && requestParam.required()) { return true; } PathVariable pathVariable = parameter.getParameterAnnotation(PathVariable.class); if (Tools.isNotBlank(pathVariable) && pathVariable.required()) { return true; } RequestBody requestBody = parameter.getParameterAnnotation(RequestBody.class); if (Tools.isNotBlank(requestBody) && requestBody.required()) { return true; } RequestAttribute requestAttribute = parameter.getParameterAnnotation(RequestAttribute.class); if (Tools.isNotBlank(requestAttribute) && requestAttribute.required()) { return true; } RequestHeader requestHeader = parameter.getParameterAnnotation(RequestHeader.class); if (Tools.isNotBlank(requestHeader) && requestHeader.required()) { return true; } RequestPart requestPart = parameter.getParameterAnnotation(RequestPart.class); if (Tools.isNotBlank(requestPart) && requestPart.required()) { return true; } SessionAttribute sessionAttribute = parameter.getParameterAnnotation(SessionAttribute.class); if (Tools.isNotBlank(sessionAttribute) && sessionAttribute.required()) { return true; } MatrixVariable matrixVariable = parameter.getParameterAnnotation(MatrixVariable.class); if (Tools.isNotBlank(matrixVariable) && matrixVariable.required()) { return true; } CookieValue cookieValue = parameter.getParameterAnnotation(CookieValue.class); return Tools.isNotBlank(cookieValue) && cookieValue.required(); }
Example 13
Source File: RequestAttributeMethodArgumentResolver.java From spring-analysis-note with MIT License | 4 votes |
@Override protected NamedValueInfo createNamedValueInfo(MethodParameter parameter) { RequestAttribute ann = parameter.getParameterAnnotation(RequestAttribute.class); Assert.state(ann != null, "No RequestAttribute annotation"); return new NamedValueInfo(ann.name(), ann.required(), ValueConstants.DEFAULT_NONE); }
Example 14
Source File: PathVariableMapMethodArgumentResolver.java From spring4-understanding with Apache License 2.0 | 4 votes |
@Override public boolean supportsParameter(MethodParameter parameter) { PathVariable ann = parameter.getParameterAnnotation(PathVariable.class); return (ann != null && (Map.class.isAssignableFrom(parameter.getParameterType())) && !StringUtils.hasText(ann.value())); }
Example 15
Source File: AbstractJackson2Decoder.java From spring-analysis-note with MIT License | 4 votes |
@Override protected <A extends Annotation> A getAnnotation(MethodParameter parameter, Class<A> annotType) { return parameter.getParameterAnnotation(annotType); }
Example 16
Source File: RequestAttributeMethodArgumentResolver.java From lams with GNU General Public License v2.0 | 4 votes |
@Override protected NamedValueInfo createNamedValueInfo(MethodParameter parameter) { RequestAttribute ann = parameter.getParameterAnnotation(RequestAttribute.class); return new NamedValueInfo(ann.name(), ann.required(), ValueConstants.DEFAULT_NONE); }
Example 17
Source File: RequestParamMethodArgumentResolver.java From java-technology-stack with MIT License | 4 votes |
@Override protected NamedValueInfo createNamedValueInfo(MethodParameter parameter) { RequestParam ann = parameter.getParameterAnnotation(RequestParam.class); return (ann != null ? new RequestParamNamedValueInfo(ann) : new RequestParamNamedValueInfo()); }
Example 18
Source File: SessionAttributeMethodArgumentResolver.java From java-technology-stack with MIT License | 4 votes |
@Override protected NamedValueInfo createNamedValueInfo(MethodParameter parameter) { SessionAttribute ann = parameter.getParameterAnnotation(SessionAttribute.class); Assert.state(ann != null, "No SessionAttribute annotation"); return new NamedValueInfo(ann.name(), ann.required(), ValueConstants.DEFAULT_NONE); }
Example 19
Source File: PathVariableMapMethodArgumentResolver.java From spring-analysis-note with MIT License | 4 votes |
@Override public boolean supportsParameter(MethodParameter parameter) { PathVariable ann = parameter.getParameterAnnotation(PathVariable.class); return (ann != null && Map.class.isAssignableFrom(parameter.getParameterType()) && !StringUtils.hasText(ann.value())); }
Example 20
Source File: CookieValueMethodArgumentResolver.java From java-technology-stack with MIT License | 4 votes |
@Override protected NamedValueInfo createNamedValueInfo(MethodParameter parameter) { CookieValue ann = parameter.getParameterAnnotation(CookieValue.class); Assert.state(ann != null, "No CookieValue annotation"); return new CookieValueNamedValueInfo(ann); }