@Test public void validateInvalidNestedNullProperty() { RootBean rootBean = new RootBean(); NestedBean nestedBean = new NestedBean(); rootBean.setNestedBean(nestedBean); Set<ConstraintViolation<RootBean>> violations = validation.validateProperty(rootBean, "nestedBean.property"); Assert.assertTrue(violations.size() == 1); }
public <T> Set<ConstraintViolation<T>> validateProperty(T object, String propertyPath, Class<?>... groups) { Set<ConstraintViolation<T>> violations = new HashSet<ConstraintViolation<T>>(); try { int currentIndex = -1; String currentPropertyPath; do { currentIndex = propertyPath.indexOf(".", ++currentIndex); if (currentIndex >= 0) { currentPropertyPath = propertyPath.substring(0, currentIndex); } else { currentPropertyPath = propertyPath; } Set<ConstraintViolation<T>> currentViolations = validator.validateProperty(object, currentPropertyPath, groups); ConstraintViolation<T> notNullViolation = findNotNullViolation(currentViolations); if (notNullViolation == null) { violations = currentViolations; } else { violations.add(notNullViolation); break; } } while (currentIndex >= 0); } catch (IllegalArgumentException e) { } return violations; }
Validation { public <T> Set<ConstraintViolation<T>> validateProperty(T object, String propertyPath, Class<?>... groups) { Set<ConstraintViolation<T>> violations = new HashSet<ConstraintViolation<T>>(); try { int currentIndex = -1; String currentPropertyPath; do { currentIndex = propertyPath.indexOf(".", ++currentIndex); if (currentIndex >= 0) { currentPropertyPath = propertyPath.substring(0, currentIndex); } else { currentPropertyPath = propertyPath; } Set<ConstraintViolation<T>> currentViolations = validator.validateProperty(object, currentPropertyPath, groups); ConstraintViolation<T> notNullViolation = findNotNullViolation(currentViolations); if (notNullViolation == null) { violations = currentViolations; } else { violations.add(notNullViolation); break; } } while (currentIndex >= 0); } catch (IllegalArgumentException e) { } return violations; } }
Validation { public <T> Set<ConstraintViolation<T>> validateProperty(T object, String propertyPath, Class<?>... groups) { Set<ConstraintViolation<T>> violations = new HashSet<ConstraintViolation<T>>(); try { int currentIndex = -1; String currentPropertyPath; do { currentIndex = propertyPath.indexOf(".", ++currentIndex); if (currentIndex >= 0) { currentPropertyPath = propertyPath.substring(0, currentIndex); } else { currentPropertyPath = propertyPath; } Set<ConstraintViolation<T>> currentViolations = validator.validateProperty(object, currentPropertyPath, groups); ConstraintViolation<T> notNullViolation = findNotNullViolation(currentViolations); if (notNullViolation == null) { violations = currentViolations; } else { violations.add(notNullViolation); break; } } while (currentIndex >= 0); } catch (IllegalArgumentException e) { } return violations; }  }
Validation { public <T> Set<ConstraintViolation<T>> validateProperty(T object, String propertyPath, Class<?>... groups) { Set<ConstraintViolation<T>> violations = new HashSet<ConstraintViolation<T>>(); try { int currentIndex = -1; String currentPropertyPath; do { currentIndex = propertyPath.indexOf(".", ++currentIndex); if (currentIndex >= 0) { currentPropertyPath = propertyPath.substring(0, currentIndex); } else { currentPropertyPath = propertyPath; } Set<ConstraintViolation<T>> currentViolations = validator.validateProperty(object, currentPropertyPath, groups); ConstraintViolation<T> notNullViolation = findNotNullViolation(currentViolations); if (notNullViolation == null) { violations = currentViolations; } else { violations.add(notNullViolation); break; } } while (currentIndex >= 0); } catch (IllegalArgumentException e) { } return violations; }  @PostConstruct void postConstruct(); Set<ConstraintViolation<T>> validate(T object, Class<?>... groups); Set<ConstraintViolation<T>> validateProperty(T object, String propertyPath, Class<?>... groups); Set<ConstraintViolation<T>> validateValue(Class<T> beanType, String propertyName, Object value, Class<?>... groups); BeanDescriptor getConstraintsForClass(Class<?> clazz); T unwrap(Class<T> type); boolean isCascaded(Class beanClass, String propertyName); boolean isRequired(Class beanClass, String propertyName); boolean hasAnnotation(Class beanClass, String propertyName, Class annotationClass); }
Validation { public <T> Set<ConstraintViolation<T>> validateProperty(T object, String propertyPath, Class<?>... groups) { Set<ConstraintViolation<T>> violations = new HashSet<ConstraintViolation<T>>(); try { int currentIndex = -1; String currentPropertyPath; do { currentIndex = propertyPath.indexOf(".", ++currentIndex); if (currentIndex >= 0) { currentPropertyPath = propertyPath.substring(0, currentIndex); } else { currentPropertyPath = propertyPath; } Set<ConstraintViolation<T>> currentViolations = validator.validateProperty(object, currentPropertyPath, groups); ConstraintViolation<T> notNullViolation = findNotNullViolation(currentViolations); if (notNullViolation == null) { violations = currentViolations; } else { violations.add(notNullViolation); break; } } while (currentIndex >= 0); } catch (IllegalArgumentException e) { } return violations; }  @PostConstruct void postConstruct(); Set<ConstraintViolation<T>> validate(T object, Class<?>... groups); Set<ConstraintViolation<T>> validateProperty(T object, String propertyPath, Class<?>... groups); Set<ConstraintViolation<T>> validateValue(Class<T> beanType, String propertyName, Object value, Class<?>... groups); BeanDescriptor getConstraintsForClass(Class<?> clazz); T unwrap(Class<T> type); boolean isCascaded(Class beanClass, String propertyName); boolean isRequired(Class beanClass, String propertyName); boolean hasAnnotation(Class beanClass, String propertyName, Class annotationClass);  }