I have following class to validate:
@Document(collection = "settings")
public class Settings {
@NotEmpty
private String[] allowableExtensions;
...
@AssertTrue(message = "Each extension must be alphanumeric string with length {2,4}")
public boolean assertTrue() {
for (String extension : allowableExtensions) {
if (extension == null || extension.matches("^[a-zA-Z0-9]{2,6}$")) {
return false;
}
}
return true;
}
}
and following controller:
@PostMapping(value = "/settings/update", consumes = "application/json")
public ResponseEntity<?> updateSettings(@RequestBody @Valid Settings settings, BindingResult bindingResult) {
if(bindingResult.hasErrors()){
return ResponseEntity.badRequest().body(bindingResult.getAllErrors().get(0).getDefaultMessage());
}
}
I didn't find expected errors and put breakpoint into assertTrue method but it doesn't invoke.
What do I wrong?