Skip to content
Advertisement

My custom validation annotation is not working in Spring Boot

i have created an annotation that has features such as checking if the entered string is null or at the assigned value.But the annotation doesn’t work. I don’t think it does any validation on the DTO.What am I doing wrong ? I also added the valid annotation on the controller. I don’t think the isValid() function works.

JavaScript
JavaScript
JavaScript
JavaScript

Advertisement

Answer

Record classes are in fact auto-generated classes with immutable fields and a getter-style method for each field. How do you know where (on a method or a field) is the annotation @SpecificStringValue placed?

The target of the annotation is only PARAMETER so i suspect that the annotation is not propagated to the field (userName), which is what will trigger the validation. You should at least try to add METHOD and FIELD to the annotation targets

Advertisement