I'm new to Spring boot development.
We are using validation groups to validate our request.
It's helpful for avoiding duplicate class creation.
Problem:
But the problem is if we need same variable for multiple group code become very larger and difficult to add another group (because we need to scroll all the classes)
If we work with the team, it creates code merging issues also.
My code:
public class RequestDto {
@Min(groups = {ConformCreateRequest.class, ConformCreateRequestInstallationAppointment.class, ConformCreateRequestInstallationCompletion.class, ConformCreateRequestIssuerCompletedBy.class, ConformCreateRequestIssuerCompleted.class, CancelCreateRequest.class, ConformCancelCreateRequest.class, StatusRequestValidator.class, ConformCancelRequestValidator.class,RescheduleCreateRequest.class,ConfirmRescheduleCreateRequest.class}, value = 1, message = EValidationErrorMessage.MISSING_FIELD)
@NotNull(groups = {ConformCreateRequestByAsherOtp.class, ConformCreateRequestInstallationAppointment.class, ConformCreateRequestInstallationCompletion.class, ConformCreateRequestIssuerCompleted.class, ConformCreateRequestIssuerCompleted.class, CancelCreateRequest.class, ConformCancelCreateRequest.class, StatusRequestValidator.class, ConformCancelRequestValidator.class,RescheduleCreateRequest.class,ConfirmRescheduleCreateRequest.class}, message = EValidationErrorMessage.MISSING_FIELD)
private Long id;
How to overcome this length issue or any other smart way to handle this?
Edit:
I'm not asking how to set Default group? I'm asking what's the best way if we have multiple validation groups. In the above example, I have 15 validation groups, In future it will increase. It's hard to add/edit a new group after it become bigger.