I have validations in my application which are built based on spring validation annotations like NotNull, NotEmpty.
public class AccountCreateRequest {
@NotNull
private String accountName;
@NotNull
@Size(max = ACCOUNT_NUMBER_CHAR_LIMIT, message = "AccountNumber should not exceed {max} characters",groups = {SqlCharLimitValidatorGroup.class})
private String accountNumber;
private String departmentType;
@NotNull
private AccountType accountTypeId;
private String accountSubTypeId;
}
It works perfectly, I can also use groups based validation for different flows.
I have different clients who want to create entities differently and want to have different validations. I do not want to create multiple groups for them. I want to store the client level config in databases and drive the validation from that config.
For example: for above request
{
asset: "Account",
client: "123",
fields: [
{
name: "accountName",
validations: ["NotNull", "NotBlank"]
},
...
]
}
For any asset, we would read the field configs from db and validate. How can I achieve it in my spring application?