Skip to content

Support @RequestParam, @RequestHeader, etc. as meta-annotations [SPR-17296] #21829

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
spring-projects-issues opened this issue Sep 22, 2018 · 6 comments
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Sep 22, 2018

Rob Winch opened SPR-17296 and commented

It would be nice if @RequestHeader could be used for a meta-annotation. This would make it easier if a header was being used consistently throughout the entire application. For example, a user might do something like this:

@Retention(RetentionPolicy.RUNTIME)
@RequestHeader(name = "user-id")
public @interface CurrentUserId {
}

No further details from SPR-17296

@spring-projects-issues spring-projects-issues added type: enhancement A general enhancement in: web Issues in web modules (web, webmvc, webflux, websocket) labels Jan 11, 2019
@spring-projects-issues spring-projects-issues added this to the 5.x Backlog milestone Jan 11, 2019
@joehitt
Copy link

joehitt commented Nov 19, 2019

Please consider also doing this for @RequestParam, so same can be done for commonly-reused request parameters. A common use case would be page number and page size for Pageable REST services:

@Target(ElementType.PARAMETER)
@Retention(RetentionPolicy.RUNTIME)
@RequestParam(name = "page", required = false)  //  currently "not applicable to annotation type"
public @interface PageNumber {
}

@sbrannen sbrannen changed the title Support for @RequestHeader as meta annotation [SPR-17296] Support @RequestParam and @RequestHeader as meta-annotations [SPR-17296] Nov 20, 2019
@sbrannen sbrannen modified the milestones: 5.x Backlog, 5.3 M1 Nov 20, 2019
@sbrannen
Copy link
Member

sbrannen commented Nov 20, 2019

Currently slated for 5.3.

We will need to assess whether such changes need to be applied to additional controller method argument annotations as well.

It may be sufficient to switch from MethodParameter to SynthesizingMethodParameter for such annotation lookups.

@sbrannen
Copy link
Member

It may be sufficient to switch from MethodParameter to SynthesizingMethodParameter for such annotation lookups.

I take that back. @RequestParam and @RequestHeader already make use of @AliasFor for attribute aliases within those annotations. Thus, SynthesizingMethodParameter (or a subclass thereof) is already in place.

In order to support these annotations as meta-annotations, we would have to allow them to be declared on annotations (i.e., @Target({ElementType.PARAMETER, ElementType.ANNOTATION_TYPE}) -- which is the easy part) and we would have to look them up using our merged annotation support instead of just looking them up as directly declared annotations (which is the more involved part... since the MethodParameter implementation would have modified considerably).

@rstoyanchev rstoyanchev modified the milestones: 5.3 M1, 5.3 M2 Jun 23, 2020
@jhoeller jhoeller modified the milestones: 5.3 M2, 5.3 RC1 Aug 8, 2020
@jhoeller jhoeller modified the milestones: 5.3 RC1, 5.x Backlog Aug 25, 2020
@bjerga
Copy link

bjerga commented Jul 8, 2021

It would be great if @PathVariable could also be used as a meta-annotation. This would be handy when a path variable is used frequently in an application, similarly to what has been mentioned for the other annotations.

@jhoeller jhoeller modified the milestones: 5.x, 6.0.x Nov 1, 2021
@sbrannen sbrannen changed the title Support @RequestParam and @RequestHeader as meta-annotations [SPR-17296] Support @RequestParam, @RequestHeader, etc. as meta-annotations [SPR-17296] Nov 1, 2021
@sbrannen
Copy link
Member

sbrannen commented Nov 1, 2021

Team Decision: we plan to support the following parameter annotations as meta-annotations in Spring Framework 6.0.

  • @CookieValue
  • @MatrixVariable
  • @ModelAttribute
  • @PathVariable
  • @RequestAttribute
  • @RequestBody
  • @RequestHeader
  • @RequestParam
  • @RequestPart
  • @SessionAttribute

Before releasing this feature, we should first assess whether there is any significant performance degradation due to the switch from simple synthesized annotations (supporting only @AliasFor semantics within a single annotation via SynthesizingMethodParameter) to fully merged annotations.

@jhoeller jhoeller modified the milestones: 6.0.x, 6.1.x Jan 11, 2023
@sbrannen sbrannen changed the title Support @RequestParam, @RequestHeader, etc. as meta-annotations [SPR-17296] Support @RequestParam, @RequestHeader, etc. as meta-annotations [SPR-17296] Aug 28, 2023
@bclozel bclozel modified the milestones: 6.1.x, 6.x Backlog Oct 25, 2023
@bclozel bclozel changed the title Support @RequestParam, @RequestHeader, etc. as meta-annotations [SPR-17296] Support @RequestParam, @RequestHeader, etc. as meta-annotations [SPR-17296] Feb 14, 2024
@jhoeller jhoeller modified the milestones: 6.x Backlog, General Backlog Oct 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

7 participants