1

I have some rest API

@GetMapping(value = "/getSomething")
public String getSomething(@RequestParam(value = "name") String name)

Caller to the API can provide multiple instances of the name parameter

/getSomething?name=something&name=somethingElse

In the API code the name variable will be received as "something,somethingElse"

Is there a way yo prevent this behavior ?

accept only one "name" parameter?

or return "400" "bad request" for such a case?

Thanks

4
  • I am just guessing here, but I think it is Http protocol issue rather then spring boot. So, I would try to see if you have ',' in your input - fail it. but then what if ',' is actually part of the input... Commented Mar 20, 2022 at 13:54
  • well as you said, the input may contain "," Commented Mar 20, 2022 at 15:00
  • 3
    Are you looking for: stackoverflow.com/questions/22817430/… ? Commented Mar 21, 2022 at 3:44
  • For permanent solution, refere as @VoiceOfUnreason mentioned, but to stop the bleeding you can do something like this -> if(Arrays.asList(name.split(",")).size()>1) { throw exception }
    – Harsh
    Commented Apr 8, 2022 at 10:29

0

Browse other questions tagged or ask your own question.