Description
Description
When using bean validation it is possible to apply groups to constraints which are annotated on fields or classes. When doing the validation it should be possible to define which group should be valided. Let me give one example: If I have a entity class it depends on the operation whether I want the id to be null or not. If it is an update I need to have the id populated (so I can find the record to be updated), if not it must be null (if it is generated in the database). As the validation is depending on the operation I can't just use @Valid on the service method and have a specific annotation on the id field. I would need both annotations on the id field, one relevant for insert, one for update operation.
Implementation ideas
The annotation could be assigned to a group:
class Entity {
@Null(groups = Create.class)
@NotNull(groups = { Update.class, Delete.class })
ObjectId id;
}
And in the service method I could somehow apply that group:
class CrudService {
persist(@Valid(Create.class) Entity) {...}
update(@Valid(Update.class) Entity) {...}
delete(@Valid(Delete.class) Entity) {...}
}
Basically I have stolen that idea from here which is refering to Spring: https://stackoverflow.com/questions/44491806/javax-validation-based-on-operation. I know the @Valid annotation can't be used like that, maybe an additional annotation could be invented? Or would you have any idea on how to make use of the groups using Quarkus and service method validation?