Grails Gotcha – Domain Field Capitalization

You should use standard camelCase names for your fields and not ProperCase.

The following gotcha only reveals itself if you do not use standard camelCase naming conventions for fields. The reason you may want to violate camelCase naming conventions is when you have a service callback where you just want to capture the params that they send to you.

Bad:

class TwilioVoice {
    String AccountSid
    static constraints = {
        AccountSid(nullable: false)
    }
}

Good:

class TwilioVoice {
    String accountSid
    static constraints = {
        accountSid(nullable: false)
    }
}

If your class has a field that starts with a capital letter and you need to use the constraints feature, you will get an error similar to this:

Message: Can not set java.lang.String field TwilioVoice.MyField to java.lang.Class

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>