I am trying to create my own validator for validating a List<String>
read from a YAML configuration file. What I want to do, is validate it against a Enum class that I have created which looks like the following:
public enum BundleName {
DK("dk.bundle"),
UK("uk.bundle"),
US("us.bundle"),
DK_DEBUG("dk.bundle.debug"),
UK_DEBUG("uk.bundle.debug"),
US_DEBUG("us.bundle.debug"),
;
private String bundleName;
BundleName(String bundleName) {
this.bundleName = bundleName;
}
public String getBundleName() {
return this.bundleName
}
}
My YAML file has the following defined:
bundleNames:
- ${DK}
- ${UK}
- ${US}
- ${DK_DEBUG}
- ${UK_DEBUG}
- ${US_DEBUG}
Now either some of these environment variables might be set or all of them might be set or just one is set. Different environment different combo. Anyway what I want is to be able to validate these environment variables against the bundleName
in enum BundleName.class
. Now Hibernate have a nice example, and also all other examples I find on the net is, where validation is done against a specific simple enum. I do not want to check on the enum name but the enum value, and I simply cannot figure out how. All what I have tried so fare is some combinations of what I found in some other posts like this and this and many more.
In my ApiConfiguration.java
I would like to end up with something like the following on my list read from YAML:
@NotNull
@BundleNameValidation(acceptedValues = BundleName.class)
private List<String> bundleNames;
If that is possible somehow.