Bean Validation Introduction

Helidon supports Bean Validation via its integration with JAX-RS/Jersey. The Jakarta Bean Validation specification defines an API to validate Java beans. Bean Validation is supported in REST resource classes as well as in regular application beans.

Maven Coordinates

To enable Bean Validation add the following dependency to your project’s pom.xml (see Managing Dependencies).

<dependency>
  <groupId>org.glassfish.jersey.ext</groupId>
  <artifactId>jersey-bean-validation</artifactId>
</dependency>
Copied

Validation Example in Helidon MP

The following example shows a simple resource method annotated with @POST whose parameter must be not null and valid. Validating a parameter in this case implies making sure that any constraint annotations in the Greeting class are satisfied. The resource method shall never be called if the validation fails, with a 400 (Bad Request) status code returned instead.

@Path("helloworld")
public class HelloWorld {

    @POST
    @Consumes(MediaType.APPLICATION_JSON)
    public void post(@NotNull @Valid Greeting greeting) {
        // ...
    }
}
Copied