How do you validate that jsonbody doesnt contain extra fields in springboot REST controller, Bean validation works on the field but it do not check if extra fields are present.
for example Model
public class User {
@NotBlank(message = "Name is mandatory")
private String name;
}
REST controller
@PostMapping(path = "/user")
public ResponseEntity addUser(@Valid @RequestBody User user) throws Exception {
userService.save(user);
return new ResponseEntity<>( HttpStatus.OK);
}
how do you validate the indata below
{
"name": "Tim",
"not_allowed": "not_allowed"
}
This code do not Validate any extra fields, just the field itself