generated from micronaut-projects/micronaut-project-template
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: avoid adding unnamed Bean node in constraint validation message …
- Loading branch information
1 parent
c28fa3f
commit c7c17af
Showing
6 changed files
with
77 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
validation/src/test/groovy/io/micronaut/validation/PojoValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package io.micronaut.validation; | ||
|
||
import java.util.Objects; | ||
import jakarta.inject.Singleton; | ||
|
||
import io.micronaut.core.annotation.AnnotationValue; | ||
import io.micronaut.core.annotation.Introspected; | ||
import io.micronaut.validation.validator.constraints.ConstraintValidator; | ||
import io.micronaut.validation.validator.constraints.ConstraintValidatorContext; | ||
|
||
@Singleton | ||
@Introspected | ||
public class PojoValidator implements ConstraintValidator<ValidPojo, Pojo> { | ||
|
||
@Override | ||
public boolean isValid(Pojo pojo, AnnotationValue<ValidPojo> annotationMetadata, | ||
ConstraintValidatorContext context) { | ||
if (Objects.equals(pojo.getEmail(), pojo.getName())) { | ||
context.messageTemplate("Email and Name can not be identical"); | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
validation/src/test/groovy/io/micronaut/validation/ValidPojo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package io.micronaut.validation; | ||
|
||
import static java.lang.annotation.ElementType.TYPE; | ||
import static java.lang.annotation.RetentionPolicy.RUNTIME; | ||
|
||
import java.lang.annotation.Documented; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.Target; | ||
import jakarta.validation.Constraint; | ||
|
||
/** | ||
* Simple annotation to validate behavior when adding validation annotation at class level | ||
*/ | ||
@Documented | ||
@Target(TYPE) | ||
@Retention(RUNTIME) | ||
@Constraint(validatedBy = {PojoValidator.class}) | ||
public @interface ValidPojo { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters