private void validate ( Object object ) { Set < ConstraintViolation < Object >> viols = validator . validate ( object ) ; for ( ConstraintViolation < Object > constraintViolation : viols ) { if ( Null . class . isAssignableFrom ( constraintViolation . getConstraintDescriptor ( ) . getAnnotation ( ) . getClass ( ) ) ) { Object o = constraintViolation . getLeafBean ( ) ; Iterator < Node > iterator = constraintViolation . getPropertyPath ( ) . iterator ( ) ; String propertyName = null ; while ( iterator . hasNext ( ) ) { propertyName = iterator . next ( ) . getName ( ) ; } if ( propertyName != null ) { try { PropertyDescriptor descriptor = BeanUtils . getPropertyDescriptor ( o . getClass ( ) , propertyName ) ; descriptor . getWriteMethod ( ) . invoke ( o , new Object [ ] { null } ) ; } catch ( Exception e ) { e . printStackTrace ( ) ; } } } } }
Take a stab at fixing validation problems ?