HV-2193: Create a new constraint @NullOrNotBlank similar to @NotBlank for use with nullable fields and Optional<> - #1906
HV-2193: Create a new constraint @NullOrNotBlank similar to @NotBlank for use with nullable fields and Optional<>#1906koentsje wants to merge 7 commits into
Conversation
…for use with nullable fields and Optional - Add the initial implementation of constraint NullOrNotBlank Signed-off-by: Koen Aers <koen.aers@gmail.com>
- Add NullOrNotBlankValidator for CharSequence validation - Add NullOrNotBlankValidatorTest covering null, not blank, empty and blank cases Signed-off-by: Koen Aers <koen.aers@gmail.com>
- Register NullOrNotBlank in BuiltinConstraint and ConstraintHelper - Add validation message to ValidationMessages.properties - Update MessagePropertiesTest and PredefinedScopeAllConstraintsTest - Add NullOrNotBlankConstrainedTest covering direct field and Optional usage Signed-off-by: Koen Aers <koen.aers@gmail.com>
- Add NullOrNotBlankDef class Signed-off-by: Koen Aers <koen.aers@gmail.com>
- Add @testForissue(jiraKey = "HV-2193") to NullOrNotBlankValidatorTest and NullOrNotBlankConstrainedTest - Add testProgrammaticDefinition test for NullOrNotBlankDef in NullOrNotBlankValidatorTest Signed-off-by: Koen Aers <koen.aers@gmail.com>
- Add NULL_OR_NOT_BLANK constant to TypeNames - Register NullOrNotBlank for CharSequence in AP ConstraintHelper - Add ModelWithNullOrNotBlankConstraints test model - Add nullOrNotBlankConstraints test to ConstraintValidationProcessorIT Signed-off-by: Koen Aers <koen.aers@gmail.com>
- Add @NullOrNotBlank entry to the reference guide in chapter 2 Signed-off-by: Koen Aers <koen.aers@gmail.com>
marko-bekhta
left a comment
There was a problem hiding this comment.
Hey @koentsje 👋🏻 🙂
thanks! looks good, let's update that since tag and merge ?
| /** | ||
| * Constraint definition for {@link NullOrNotBlank}. | ||
| * @author Koen Aers | ||
| * @since 9.1 |
There was a problem hiding this comment.
| * @since 9.1 | |
| * @since 9.2 |
as 9.1 is already out, we'll add it to the 9.2 🙂
| * (extracted as {@code null}) should be valid, but a present value must not be blank. | ||
| * | ||
| * @author Koen Aers | ||
| * @since 9.1 |
There was a problem hiding this comment.
| * @since 9.1 | |
| * @since 9.2 |
and here 🙂
|
Hi! Thanks for this useful addition. I raised this topic back in November on the mailing list and opened an issue in the Jakarta Validation project. Just wanted to check: are there any plans to introduce |
|
@marko-bekhta ping. |
|
|
@marko-bekhta I believe this PR can be closed now, right? |
|
@koentsje yes, thanks for the reminder 🙂 |



Add a new Hibernate Validator specific constraint @NullOrNotBlank that validates a character sequence is either null or contains at least one non-whitespace character.
See: https://hibernate.atlassian.net/browse/HV-2193
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on licensing, please check here.