Skip to content

Commit

Permalink
Unwrap a validator instance of specified type contained in SpringVali…
Browse files Browse the repository at this point in the history
…datorAdapter

See gh-37081.
  • Loading branch information
zpavloudis committed Aug 31, 2023
1 parent f1f4e9c commit aa44626
Showing 1 changed file with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
*
* @author Stephane Nicoll
* @author Phillip Webb
* @author Zisis Pavloudis
* @since 2.0.0
*/
public class ValidatorAdapter implements SmartValidator, ApplicationContextAware, InitializingBean, DisposableBean {
Expand Down Expand Up @@ -153,4 +154,20 @@ private static Validator wrap(Validator validator, boolean existingBean) {
return validator;
}

@Override
@SuppressWarnings("unchecked")
public <T> T unwrap(Class<T> type) {
if (this.target == null) {
return null;
}
if (type.isAssignableFrom(this.target.getClass())) {
if (this.target instanceof SpringValidatorAdapter adapter) {
return adapter.unwrap(type);
}
return (T) this.target;
}

throw new ValidationException("Cannot unwrap to " + type);
}

}

0 comments on commit aa44626

Please sign in to comment.