0

I have a scenario where I have to rename one required request param. My application is already live. I want to deprecate the existing request param and want to add new request parameter. So my existing applications will be sending me the old request parameter and new application will start to send the new param. Now I want to add validation, either I can mark both params as required or optional. But my business logic is either of param is required.

For example I already have a path parameter group and now I want to rename it to pageGroup. So either page or pageGroup is required.

How can I achieve it in Spring Boot? Any suggestions are welcome :)

Amjad Aziz
  • 103
  • 8
  • Do you have a path parameter or request parameter as those are different things. Just write 2 handler methods each with a different parameter name and a `param` in the `@RequestMapping` annotation. – M. Deinum Nov 01 '22 at 17:33
  • @M.Deinum I am dealing with request parameter so I think I can not add two different handler methods as path is not changing. – Amjad Aziz Nov 01 '22 at 17:49
  • Yes you can, read my comment add the `param` argument to the `@RequestMapping` annotation. – M. Deinum Nov 01 '22 at 17:50
  • @M.Deinum I have added a different handlers for both parameters using `params` and it worked perfectly. It might be a noob question for you but I was not aware of this :) Thanks man! – Amjad Aziz Nov 01 '22 at 18:10
  • @M.Deinum I have another case, I can receive both parameters. In this case I am getting an exception :) Ambiguous handler methods mapped – Amjad Aziz Nov 01 '22 at 18:22
  • Hey @AmjadAziz can you share a code snippet of your solution to have an overview? Will be helpful – doc Nov 01 '22 at 18:53
  • If you do both parameters that won't be possible as, as you noticed, Spring cannot determine which method to call. Instead of using `@RequestParam` you can also manually extract the parameters from the `HttpServletRequest` and do the handling in the method. – M. Deinum Nov 02 '22 at 07:09

0 Answers0