0

I have problem on checking equals between query string from url to request param name.

For example providing the status attribute in Postman will be as below:

http:localhost:8080/foo?Status=COMPLETED

But the controller method has the following:

@GetMapping(value = "/foo")
@ResponseStatus(code = HttpStatus.OK)
public void getSomething(@RequestParam(name="status") Optional<Enum[]> status) {
    //Something
}

Expected Solution: The param name provided in url should match the @RequestParam(name="status") which is case sensitive.

Note: This is purely a Spring project (even no spring-web-mvc) - no usages of Spring Boot and Hibernate.

İsmail Y.
  • 3,579
  • 5
  • 21
  • 29
eThan_hunT
  • 244
  • 5
  • 23
  • Does this answer your question? [RequestParam value in spring MVC to be case insensitive](https://stackoverflow.com/questions/8922371/requestparam-value-in-spring-mvc-to-be-case-insensitive) – Ka'Eios Aug 14 '23 at 08:08
  • I dont think case insensitivity is supported for that. You could however map all parameters like so `@RequestParam Map allParams` and then check if the keyset contains the string you are looking for. Though you will have to use a TreeMap and the String CASE_INSENSITIVE_ORDER – experiment unit 1998X Aug 14 '23 at 08:10
  • i dont think this is really recommended as its like jumping through hoops when you can just ensure your client and server follows same standards – experiment unit 1998X Aug 14 '23 at 08:11
  • @experimentunit1998X I have lots of controller so this requires to handle for all request param names which is hectic one- do we have any common way or predefined way to handle this – eThan_hunT Aug 14 '23 at 08:15

1 Answers1

0

Unfortunately Spring's @RequestParam is case sensitive, and rewriting the controllers to avoid that would be a fair amount of work.

So, instead, you can do this by adding a servlet filter:

In your case the variable is status, so for every request it will convert it as per your variable setter method camel case injection and then match as per your request.

Just try for your custom requirements:

https://stackoverflow.com/a/32525732/2039546

İsmail Y.
  • 3,579
  • 5
  • 21
  • 29
  • It is not Spring that is case sensitive but the servlet API. `status` and `Status` are different parameters according to that. – M. Deinum Aug 14 '23 at 10:01