Skip to content

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

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

Closed
spring-projects-issues opened this issue Mar 4, 2016 · 7 comments
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) status: duplicate A duplicate of another issue

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Mar 4, 2016

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

@spring-projects-issues
Copy link
Collaborator Author

Greg Turnquist commented

Moved to Spring Framework since this involves Spring MVC.

@spring-projects-issues
Copy link
Collaborator Author

Paul commented

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

@spring-projects-issues
Copy link
Collaborator Author

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)?

@spring-projects-issues
Copy link
Collaborator Author

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.

@spring-projects-issues
Copy link
Collaborator Author

Paul commented

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

@spring-projects-issues
Copy link
Collaborator Author

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.

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented Mar 8, 2016

Rossen Stoyanchev commented

Resolving as duplicate of #15682.

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) status: duplicate A duplicate of another issue
Projects
None yet
Development

No branches or pull requests

2 participants