I have a simple method to get a list of documents for a given companyId
. Here is the method:
@Override
public List<Documents> getDocumentList(@NotNull Integer companyId) {
Company company = new Company(companyId);
return this.documentRepository.findByCompany(company);
}
I wanted to use Javax validation constraints to ensure that the companyId
being passed in, is not null
. But it seems to not have any effect, as I'm able to pass in a null
value, and it flows down to the findByCompany
call on the repository. I also added @Valid
before @NotNull
to force validation, but that too didn't do anything.
I could always write a couple of lines to check for a null
value, but wanted to use javax.validation
annotations to make the code more readable and concise. Is there a way to make the annotations work on method params?
To activate parameter validation, simply annotate the class with @Validated
import org.springframework.validation.annotation.Validated;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With