Grails performs validation via a Domain's constraints block. For example:
class User {
String username
String password
static constraints = {
username nullable: false, maxSize: 50, email: true
password nullable: false, maxSize: 64
}
}
See documentation.
Validation is performed during a couple of different actions on the domain:
user.save() // validates and only persists if no errors
user.validate() // validates only
Again, see the documentation. This is similar to what Spring's @Valid
does. Looking at its documentation, it states:
Spring MVC will validate a @Valid object after binding so-long as an
appropriate Validator has been configured.
What makes this basically the same as what Grails is doing is that it occurs after binding. For JSON/XML to Domain object conversion, it is really as simple as this:
def jsonObject = request.JSON
def instance = new YourDomainClass(jsonObject)
See this answer here.