use of org.mongodb.morphia.mapping.validation.ConstraintViolation in project morphia by mongodb.
the class ContainsEmbeddedWithId method checkRecursivelyHasNoIdAnnotationPresent.
private void checkRecursivelyHasNoIdAnnotationPresent(final Set<Class<?>> classesToInspect, final HashSet<Class<?>> alreadyInspectedClasses, final MappedClass mc, final Set<ConstraintViolation> ve) {
for (final Class<?> clazz : classesToInspect) {
if (alreadyInspectedClasses.contains(clazz)) {
continue;
}
if (hasTypeFieldAnnotation(clazz, Id.class)) {
ve.add(new ConstraintViolation(Level.FATAL, mc, getClass(), "You cannot use @Id on any field of an Embedded/Property object"));
}
alreadyInspectedClasses.add(clazz);
final Set<Class<?>> extraClassesToInspect = new HashSet<Class<?>>();
for (final Field field : ReflectionUtils.getDeclaredAndInheritedFields(clazz, true)) {
if (isFieldToInspect(field)) {
extraClassesToInspect.add(field.getType());
}
}
checkRecursivelyHasNoIdAnnotationPresent(extraClassesToInspect, alreadyInspectedClasses, mc, ve);
}
}
use of org.mongodb.morphia.mapping.validation.ConstraintViolation in project morphia by mongodb.
the class MapNotSerializable method check.
@Override
protected void check(final Mapper mapper, final MappedClass mc, final MappedField mf, final Set<ConstraintViolation> ve) {
if (mf.isMap()) {
if (mf.hasAnnotation(Serialized.class)) {
final Class<?> keyClass = ReflectionUtils.getParameterizedClass(mf.getField(), 0);
final Class<?> valueClass = ReflectionUtils.getParameterizedClass(mf.getField(), 1);
if (keyClass != null) {
if (!Serializable.class.isAssignableFrom(keyClass)) {
ve.add(new ConstraintViolation(Level.FATAL, mc, mf, getClass(), "Key class (" + keyClass.getName() + ") is not Serializable"));
}
}
if (valueClass != null) {
if (!Serializable.class.isAssignableFrom(valueClass)) {
ve.add(new ConstraintViolation(Level.FATAL, mc, mf, getClass(), "Value class (" + valueClass.getName() + ") is not Serializable"));
}
}
}
}
}
Aggregations