Search code examples
javaspring-bootfeign

SpringBoot Method has too many Body parameters


I created feign client for call my RestApi. When I try to run my service I receive error from this requestMethod Method has too many Body parameters For @RequestBody I used just Object type, becaues each time I can send another body request.

@RequestMapping(path = "/v1/products/{product}/companies/{companyId}", method = RequestMethod.POST,
            consumes = "application/json", produces = "application/json")
    ResponseEntity<Object> createProduct(URI baseUri,
                                         @HeaderParam("tenant-id") String tenantId,
                                         @PathVariable("product") String product,
                                         @PathVariable("companyId") String companyId,
                                         @RequestBody Object reqBody);

Solution

  • You can't use Object as the type, Please try to specify with our Class.The framework can't known which entity to use as response.

    @RequestMapping(path = "/v1/products/{product}/companies/{companyId}", method = RequestMethod.POST,
                consumes = "application/json", produces = "application/json")
        ResponseEntity<MyEntity> createProduct(URI baseUri,
                                             @HeaderParam("tenant-id") String tenantId,
                                             @PathVariable("product") String product,
                                             @PathVariable("companyId") String companyId,
                                             @RequestBody Object reqBody);