user18503943
user18503943

Reputation: 1

How to resolve java.util.Map as a paramter of @RestController method in spring boot

I have method in like below:

@RestController
public class Controller {

    @GetMapping("/test/map")
    public void testMap(@RequestParam String params, @RequestParam List<String> list, @RequestParam(name = "map") Map<String, String> map) {

        System.out.println("map >>> " + map);
        System.out.println("params >>> " + params);
        System.out.println("list >>> " + list);
    }

}

I send request with url: https://localhost:8080/test/map?params=stringParam&list=va1,val2,val3&map=param1:val1,param2:val2 and I get an error:

org.springframework.web.method.annotation.MethodArgumentConversionNotSupportedException: Failed to convert value of type 'java.lang.String' to required type 'java.util.Map'; nested exception is java.lang.IllegalStateException: Cannot convert value of type 'java.lang.String' to required type 'java.util.Map'

There is a way to resolve java.util.Map as a single parameter?

I tried to modify url but with no results.

Upvotes: 0

Views: 196

Answers (0)

Related Questions