KValidation
KValidation copied to clipboard
Enhancement: allow users to extend PropertyValidatorBase.kt and create own Validators
I am surprised I cannot create my own reusable Validators. Maybe there is some technical reason I am missing that this is kept internal? If not it would be really nice to create one's own.
Yes, makes sense. Will add it in the next version. Thanks
EDIT:
You know that PropertyValidator interface is public? You can create your own validator with that. PropertyValidatorBase is kept internal because this is the base case for built in validator classes that are exposed in RuleBuilder functions.
I just found out that com.markodevcic.kvalidation.RuleBuilder#mustBe and com.markodevcic.kvalidation.RuleBuilder#setValidator can be used to add a custom validator:
validator.forProperty { t -> t.name }.mustBe { name -> name != null }
or
validator.forProperty { t -> t.name }.setValidator(myValidator)
myValidator implements com.markodevcic.kvalidation.validators.PropertyValidator so you can also customize other methods as well.