Created
February 17, 2020 12:55
-
-
Save asouza/4132867201597f8db85411030dd12c3f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public CustomValidtor implements Validator { | |
public void validate(Object currentForm, Errors validationErrors) { | |
//O spring já espera que você mexa na referência de Errors passada com argumento e isso muda tudo. | |
if(...) { | |
validationErrors.rejectValue("fieldName","customKey", "defaultMessage"); | |
} | |
} | |
} | |
///// simulando o spring validator | |
public class ExecuteValidation { | |
public void execute(Object currentForm) { | |
Errors errors = new ValidationErrors(); | |
Set<Validator> validators = //carrega validators | |
validators.foreach(validator -> validator.validate(currentForm,errors)); | |
//a expectativa faz toda diferença. Ta no design do código a espera pela alteração da referência. Coisa que não acontece para o domínio. | |
if(errors.hasErrors()){ | |
//retorna 400 com o conjunto de erros encontrados. | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment