I have a following controllerClass, which takes a request and process it. It works fine with below code.
@RestController
@RequestMapping("/user/id")
public class UserController {
private final UserName userName;
@Autowired
public UserController(final UserName userName) {
this.userName = Objects.requireNonNull(userName, "Not found");
}
@JsonRequestMapping(method = POST)
public ResponseEntity<UserResponse> validate(
@RequestBody UserRequest UserRequest,
@RequestHeader(required = false) String validation) {
…
}
However, I want to add a validation to check request size, to avoid extra-large malicious requests being made, and reject the request if size exceeds a particular value.
I tried:
import javax.validation.constraints.Size;
…
@RequestBody(@Size(max = 200)) UserRequest UserRequest
But this is giving me Cannot find method 'value'
, which I am not sure why. Is this the right way to achieve the validation that i want, if yes what am i missing with above?