I am getting below error while running API from swagger:
2023-09-14 14:38:07.208 WARN 45800 --- [nio-8080-exec-4] m.w.r.a.GlobalControllerExceptionHandler : Error = [Missing Required Field(s). Please refer to the API documentation] Exception = [Required request parameter 'documentIds' for method parameter type List is not present]
2023-09-14 14:38:07.217 WARN 45800 --- [nio-8080-exec-4] m.w.r.a.GlobalControllerExceptionHandler : Exception
org.springframework.web.bind.MissingServletRequestParameterException: Required request parameter 'documentIds' for method parameter type List is not present
at org.springframework.web.method.support.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:122) ~[spring-web-5.3.27.jar:5.3.27]
at org.springframework.web.method.support.InvocableHandlerMethod.getMethodArgumentValues(InvocableHandlerMethod.java:179) ~[spring-web-5.3.27.jar:5.3.27]
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:146) ~[spring-web-5.3.27.jar:5.3.27]
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:117) ~[spring-webmvc-5.3.27.jar:5.3.27]
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:895) ~[spring-webmvc-5.3.27.jar:5.3.27]
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:808) ~[spring-webmvc-5.3.27.jar:5.3.27]
Below is my controller code and request data that I am passing from swagger
@RequestMapping(method = {RequestMethod.POST}, value = "/updateDocumentIds", headers = "Accept=application/json")
@ResponseBody
public ActionResult updateDocumentIds(@CustomRequestParam(value = "documentIds",required = true) List<String> documentIds, @RequestParam(value = "route") Boolean route) throws Exception {
ActionResult actionResult = new ActionResult();
//runs service method
return actionResult;
}
swagger request
Any help appreciated!
Instead of using @CustomRequestParam
we can use @Requestbody
annotation, this will copy the data into list.