Skip to content

Clarification Needed on Using forEachIfPresent for Null/Empty Checks and Cross-Field Validation #410

Answered by making
hrstoyanov asked this question in Q&A
Discussion options

You must be logged in to vote

Does it means that the validation will work if the emails list itself is not empty/null only, or does it mean it will skip NULL/empty email string elements?

IfPresent means if the fields is not null.

https://yavi.ik.am/#constraints-on-elements-in-a-collection-map-array

If the collection / map / array field is nullable, use forEachIfPresent instead of forEach.

If list is not null, validation will be run on each element, but if it is empty, nothing will happen a s a result.

https://yavi.ik.am/#built-in-constraints
Most built-in constraints, except notXXXX, do not validate fields if they are null. All examples include the case where the fields are null.

Also I do not like the "e->e" stu…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by hrstoyanov
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants