-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce ConstructorValidatorFactory
- Loading branch information
Ted Liang
committed
May 23, 2021
1 parent
63e57b0
commit c9e2028
Showing
15 changed files
with
100 additions
and
244 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
9 changes: 9 additions & 0 deletions
9
src/main/java/org/unbrokendome/jackson/beanvalidation/ConstructorValidatorFactory.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,9 @@ | ||
package org.unbrokendome.jackson.beanvalidation; | ||
|
||
import javax.validation.Validator; | ||
import javax.validation.ValidatorFactory; | ||
import java.lang.reflect.Constructor; | ||
|
||
public interface ConstructorValidatorFactory { | ||
Validator getValidator(ValidatorFactory validatorFactory, Constructor constructor, Object[] parameterValues); | ||
} |
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
13 changes: 0 additions & 13 deletions
13
src/main/java/org/unbrokendome/jackson/beanvalidation/ValidationContextHolder.java
This file was deleted.
Oops, something went wrong.
42 changes: 0 additions & 42 deletions
42
src/main/java/org/unbrokendome/jackson/beanvalidation/constraints/NotBlankWhen.java
This file was deleted.
Oops, something went wrong.
27 changes: 0 additions & 27 deletions
27
src/main/java/org/unbrokendome/jackson/beanvalidation/constraints/NotBlankWhenValidator.java
This file was deleted.
Oops, something went wrong.
41 changes: 0 additions & 41 deletions
41
src/main/java/org/unbrokendome/jackson/beanvalidation/constraints/NotNullWhen.java
This file was deleted.
Oops, something went wrong.
26 changes: 0 additions & 26 deletions
26
src/main/java/org/unbrokendome/jackson/beanvalidation/constraints/NotNullWhenValidator.java
This file was deleted.
Oops, something went wrong.
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
19 changes: 19 additions & 0 deletions
19
...g/unbrokendome/jackson/beanvalidation/constraints/HibernateConstructorValidatorFactory.kt
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 org.unbrokendome.jackson.beanvalidation.constraints | ||
|
||
import org.hibernate.validator.HibernateValidatorFactory | ||
import org.unbrokendome.jackson.beanvalidation.ConstructorValidatorFactory | ||
import java.lang.reflect.Constructor | ||
import javax.validation.Validator | ||
import javax.validation.ValidatorFactory | ||
|
||
class HibernateConstructorValidatorFactory : ConstructorValidatorFactory { | ||
override fun getValidator(validatorFactory: ValidatorFactory, constructor: Constructor<Any>, parameterValues: Array<out Any>): Validator { | ||
val declaredFields = constructor.declaringClass.declaredFields | ||
val payload: Map<String, Any> = parameterValues | ||
.mapIndexed { index, value -> declaredFields[index].name to value} | ||
.toMap() | ||
|
||
return validatorFactory.unwrap(HibernateValidatorFactory::class.java) | ||
.usingContext().constraintValidatorPayload(payload).validator | ||
} | ||
} |
Oops, something went wrong.