Validation Extension

This is a simple extension to Morphia to process JSR 303 Validation Annotations.

Using

Add this at the start of your application (or wherever you create your morphia instances).

new ValidationExtension(morphia);

``

Example

Here is a simple example using (as an example) Hibernate validation:

...
import org.hibernate.validator.constraints.Email;
...

@Entity
public class Userlike {
	@Id ObjectId id;
	@Email String email;
}

Implementation

This is a lightweight wrapper around the JSR 303 API. It installs a simple global entity interceptor which listens to all life cycle methods needed for validation. You can use any implementation of JSR 303 by just adding it to the classpath.

You can look at the code here.

Dependencies

Maven

If you use Maven to manage your project, you can reference Morphia as a dependency:

<dependency>
    <groupId>dev.morphia.morphia</groupId>
    <artifactId>validation</artifactId>
    <version>1.6.1</version>
</dependency>