According to this link:
If you need to validate entities outside of resource endpoints, the validator can be accessed in the Environment when the application is first ran.
Which means that the @Valid
below won't work and I have to programatically use the validator on the profile
object and do something with the errors that come back:
public class ProfilesManager {
...
public void createProfile(@Valid Profile profile) {
Set<ConstraintViolation<Profile>> errors = validator.validate(profile);
...
}
}
In Spring Boot, all I have to do is annotate it with @Validated
and a ConstraintViolationException
will automatically be thrown:
@Validated
@Component
public class ProfilesManager {
public void createProfile(@Valid Profile profile) {
// if invalid, exception thrown before getting here
}
}
Is there an equivalent solution for Dropwizard, official or 3rd party?