- General Bean Validation
If bean validation is required outside JAX-RS/Jersey use cases, it is also available in Helidon. It follows the standard Jakarta Bean Validation specification which defines an API to validate Java beans.
Maven Coordinates
To enable General Bean Validation add the following dependency to your project’s pom.xml (see Managing Dependencies).
<dependency>
<groupId>io.helidon.microprofile.bean-validation</groupId>
<artifactId>helidon-microprofile-bean-validation</artifactId>
</dependency>Validation Example in Helidon MP
The following example shows a simple application with one field declared as not null using @NotNull annotation:
public class GreetingHolder {
@NotNull
private String greeting;
//...
}If the bean contains a method parameter annotated with @Valid, and GreetingHolder with null_greeting is passed, then a _ValidationException will be thrown:
@ApplicationScoped
public class GreetingProvider {
private GreetingHolder greetingHolder;
//..
void setGreeting(@Valid GreetingHolder greetingHolder) {
this.greetingHolder = greetingHolder;
}
}beans.xml is required to identify beans and for bean validation to work properly.
For more information about the supported validations, see Jakarta Bean Validation specification.