Make kiwi's validation annotations in kiwi usable in collections #681
Closed
sleberknight
started this conversation in
Ideas
Replies: 1 comment
-
This "just works", for example suppose we have the following contrived class: @Value
static class HolderOfNumbers {
@NotBlank
String name;
List<@IntValue String> numberList;
Set<@IntValue String> numberSet;
Map<@IntValue String, @IntValue String> numberMap;
} This class uses kiwi's Then suppose we have a var holder = new HolderOfNumbers(
"",
List.of("foo", "bar", "baz"),
Sets.newLinkedHashSet(null, "goo"),
KiwiMaps.newLinkedHashMap(
null, "val1",
"2", "42",
"3", "63",
"4", "oops",
"badkey", "105",
"blue", "green"
)
); We can validate it and print the results: var violations = KiwiValidations.validate(holder);
for (var violation : violations) {
var propertyName = violation.getPropertyPath().toString();
var invalidValue = violation.getInvalidValue();
var message = violation.getMessage();
System.out.printf("%s with invalid value '%s' %s%n", propertyName, invalidValue, message);
} The results are:
So, there is actually nothing to do here, since Jakarta Bean Validation 3.x works out of the box. And this was actually introduced in Beans Vaidation 2.0, so it has worked for a while! |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
For examples, see this article: https://www.baeldung.com/bean-validation-container-elements (and of course the first google result was on Baeldung)
It lets you do this:
In the above
emailAddresses
can't be empty (or null), and each list element must not be blank.See
@NotBlank
or any of the standard Java Beans Validation annotations that support this.Assuming we want to to do this, we should probably break it up into one task per annotation for smaller commits.
Beta Was this translation helpful? Give feedback.
All reactions