jakartaee / jakartaee/validation

Support the Valid annotation on parameterized types to an interface class

Open
#186 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
163
Forks
67
Avg merge
3d 15h
Merged PRs (30d)
2

Description

Please add this in Jakarta EE 11. It is needed by Jakarta Data.

When performing method validation on methods that came from an interface and you don't control the interface yourself, it is currently not possible to request cascading validation on the parameters and return value of the method. The proposal is to support annotating type parameter(s) with `@Valid` when inheriting from the interface in order to request that cascading validation be automatically performed during method validation for parameters and return values of the annotated type.

For example, Jakarta Data has a built-in interface CrudRepository, which defines a very commonly used save operation, which is where validation of constraints on the passed-in entity parameter is often desired. Jakarta Data repositories that the user defines inherit from this interface, for example,

```
@Repository
public interface School extends CrudRepository {
... // inherits save(Student) operation from CrudRepository
}

@Entity
public class Student {
@Email
public String email;
@NotBlank
public String name;
@Id
public int studentId;
}
```

The user who defines this class, would like to annotate the `Student` parameter with `@Valid`, as follows:

```
@Repository
public interface School extends CrudRepository<@Valid Student, Integer> {
... // inherits save(Student) operation from CrudRepository
}
```

which we would like to see cause the constraints of the `Student` class to be validated when a `Student` object is supplied to:

```
school.save(student);
```

Mailing list discussion:
https://www.eclipse.org/lists/bean-validation-dev/msg00029.html

Contributor guide

Open the contributing guide

Research direction

Start with the issue's Jakarta Data CrudRepository example and read the linked Bean Validation mailing-list discussion. Define how @Valid on parameterized types inherited from an interface should affect method parameter and return-value validation, then verify the behavior against the Student and School examples for Jakarta EE 11.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
backend-api-design
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.