How to validate a class not under my control in a web flux controller? I'm implementing PATCH and the controller function accepts a
@RequestBody @ValidJsonPatch patch: JsonPatch
I've created the validation annotation and constraint validator:
@Constraint(validatedBy = [JsonPatchValidator::class])
annotation class ValidJsonPatch(
val message: String = "",
val groups: Array<KClass<*>> = [],
val payload: Array<KClass<out Payload>> = [],
)
class JsonPatchValidator : ConstraintValidator<ValidJsonPatch, JsonPatch> {
override fun isValid(value: JsonPatch, context: ConstraintValidatorContext): Boolean { ... }
}
But the validator never gets invoked.
I've added
_implementation_("org.springframework.boot:spring-boot-starter-validation")
to my dependencies and standard jakarta validation annotations work.
edit: scratch that... standard validation annotations are also not working.