@ -25,6 +25,8 @@ import java.util.Map;
@@ -25,6 +25,8 @@ import java.util.Map;
import java.util.Set ;
import java.util.TreeMap ;
import javax.validation.ConstraintViolation ;
import javax.validation.ValidationException ;
import javax.validation.Validator ;
import javax.validation.metadata.BeanDescriptor ;
import javax.validation.metadata.ConstraintDescriptor ;
@ -39,13 +41,19 @@ import org.springframework.validation.ObjectError;
@@ -39,13 +41,19 @@ import org.springframework.validation.ObjectError;
import org.springframework.validation.SmartValidator ;
/ * *
* Adapter that takes a JSR - 303 { @code javax . validator . Validator }
* and exposes it as a Spring { @link org . springframework . validation . Validator }
* Adapter that takes a JSR - 303 { @code javax . validator . Validator } and
* exposes it as a Spring { @link org . springframework . validation . Validator }
* while also exposing the original JSR - 303 Validator interface itself .
*
* < p > Can be used as a programmatic wrapper . Also serves as base class for
* { @link CustomValidatorBean } and { @link LocalValidatorFactoryBean } .
*
* < p > Note that Bean Validation 1 . 1 ' s { @code # forExecutables } method isn ' t supported
* on this adapter : We do not expect that method to be called by application code ;
* consider { @link MethodValidationInterceptor } instead . If you really need programmatic
* { @code # forExecutables } access , call { @code # unwrap ( Validator . class ) which will
* provide the native { @link Validator } object with { @code # forExecutables } support .
*
* @author Juergen Hoeller
* @since 3 . 0
* /
@ -297,7 +305,16 @@ public class SpringValidatorAdapter implements SmartValidator, javax.validation.
@@ -297,7 +305,16 @@ public class SpringValidatorAdapter implements SmartValidator, javax.validation.
@SuppressWarnings ( "unchecked" )
public < T > T unwrap ( Class < T > type ) {
Assert . state ( this . targetValidator ! = null , "No target Validator set" ) ;
return ( type ! = null ? this . targetValidator . unwrap ( type ) : ( T ) this . targetValidator ) ;
try {
return ( type ! = null ? this . targetValidator . unwrap ( type ) : ( T ) this . targetValidator ) ;
}
catch ( ValidationException ex ) {
// ignore if just being asked for plain Validator
if ( Validator . class = = type ) {
return ( T ) this . targetValidator ;
}
throw ex ;
}
}