0

I am migrating my spring boot application from 1.5.x to 2.3.x. After updating the required dependencies, in a controller having below method, getting one error:

@RequestMapping(value= "/test", method = RequestMethod.POST)
public ResponseEntity<MyResult> getTestRes(
                                       @RequestParam("test1") final String test1,
                                       @RequestParam("test2") final String test2,
                                       @RequestParam("test3") final String test3,
                                       @RequestParam Map<String, String> reqParam,
                                       final HttpServeletRequest req) throws Exception {

        //method body.....
}

When i try to build the application, i get below error:

[ERROR] Cant use non-primitive type: java.util.Map<java.lang.String, java.lang.String> as request parameter.

I am using Spring boot 2.3.9.RELEASE version with Spring framework 5.2.13.RELEASE.

Please let me know how can i resolve this issue.

Thanks

6
  • I think the error is clear: you can't use Map as a request parameter. Commented Jun 28, 2021 at 14:12
  • But it was working with old version and i dont see any changes regarding this kind of change in release notes. Please tell me what could be a possible fix for this error. Commented Jun 28, 2021 at 14:16
  • Are you sure you are getting the error during the Maven/Gradle build? Created minimal viable app here to replicate the issue, but build passed and even getting the response. Used spring-boot-starter-parent 2.3.9.RELEASE only. Commented Jun 28, 2021 at 15:24
  • @sas...Yes, i am just trying mvn clean install. Thanks for your effort in replication. Actually same code was working with Spring boot 1.5.1.Release but i really have no idea why its not working with 2.3.9.Release. Commented Jun 28, 2021 at 17:36
  • You can have an object to gather all your request parameters but I'm not sure if mixing is allowed. Commented Jun 28, 2021 at 21:30

1 Answer 1

0

Since you are using POST, I suggest you to do something like:

@RequestMapping(value = "/deleteData",method = RequestMethod.POST,consumes = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public Result getTestRes(@RequestBody HashMap<String, Object> dataHashMap) {
Object1 object1=  (Object1) JsonConvertor.jsonToObject((String) dataHashMap.get("object1"), Object1.class);
    Object2 object2= (Object2) JsonConvertor.jsonToObject((String) dataHashMap.get("object2"), Object2.class);   
}

Somthing like above should work. BUT if not you can have a wrapper object and pass that hashmap as key value string from client and then parse in in Java to a hashmap.

Sign up to request clarification or add additional context in comments.

1 Comment

I guess this is the solution if nothing works. But i really wants to know the root cause. At least some change notes in the subsequent spring boot releases.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.