Skip to content

Inconsistent interpretation of parameter annotations in interface-based handler methods [SPR-14021] #18593

Closed

Description

@spring-projects-issues

Paul opened SPR-14021 and commented

If I have Spring MVC interface with methods, whose params are annotated with different param types like this:

public interface PersonAPIEndpoint {
  @RequestMapping(
      path = "/person/{username}/",
      method = RequestMethod.GET
  )
  DeferredResult<PersonWithOrganizationalUnitsDTO> loadUserByUsername(@PathVariable("username") String username);

  @RequestMapping(
      path = "/person",
      method = RequestMethod.GET
  )
  DeferredResult<DataPage<PersonDTO>> listPersons(@RequestParam("pageNum") int pageNum, @RequestParam("pageSize") int pageSize, @RequestParam(value = "query", required = false) String query);

and class, which is derived from this interface, but arguments of methods are not annotated with Param annotations mapper behaviour is inconsistent:
values, annotated with @RequestParam get their values in implementing class, and with @PathVariable — not.


Issue Links:

Referenced from: commits spring-attic/spring-framework-issues@bfbb943, spring-attic/spring-framework-issues@de6f178

Activity

  1. spring-projects-issues commented on Mar 5, 2016

    @spring-projects-issues
    CollaboratorAuthor

    Greg Turnquist commented

    Moved to Spring Framework since this involves Spring MVC.

  2. spring-projects-issues commented on Mar 5, 2016

    @spring-projects-issues
    CollaboratorAuthor

    Paul commented

    I'm sorry, didn't know where to post it to.
    Thank you for your help.

  3. spring-projects-issues commented on Mar 7, 2016

    @spring-projects-issues
    CollaboratorAuthor

    Rossen Stoyanchev commented

    Annotations on method parameters are expected to be in the implementing class. I'm not sure why @RequestParam works. Could you provide a sample project (the repro repository might help)?

  4. spring-projects-issues commented on Mar 8, 2016

    @spring-projects-issues
    CollaboratorAuthor

    Paul commented

    Now, when Spring Cloud project exists — it's good idea to have single interface for endpoint and FeignClient, because client is declarative and is being build depending on annotations.

  5. spring-projects-issues commented on Mar 8, 2016

    @spring-projects-issues
    CollaboratorAuthor

    Paul commented

    Reproduce tests in pull request: spring-attic/spring-framework-issues#120

  6. spring-projects-issues commented on Mar 8, 2016

    @spring-projects-issues
    CollaboratorAuthor

    Rossen Stoyanchev commented

    Sorry for not seeing this right away but @RequestParam is the default for simple types. As long as the method argument name matches the request parameter name, it just works and the annotation doesn't have to be present. In other words you can remove those annotations and it would still work.

  7. spring-projects-issues commented on Mar 8, 2016

    @spring-projects-issues
    CollaboratorAuthor

    Rossen Stoyanchev commented

    Resolving as duplicate of #15682.

  8. added
    type: bug
    status: duplicate
    in: web
    on Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

in: webstatus: duplicate

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions