How do I set a fixed length String in Grails constraints?

I have this domain class

class Client {
  String idCard
  ...

  static constraints = {
    idCard size:16
    ...
  }
}

      

I created some test data in bootstrap.groovy file

But I am getting the following error

Caused by IllegalArgumentException: Parameter for constraint [size] of property [idCard] of class [class ni.sb.Client] must be a of type [groovy.lang.IntRange]

      

I need this property to be a string and have a fixed length

I follow the documentation size limits with no success

Thank you for your time

+3


source to share


1 answer


you can use

static constraints = {
    idCard maxSize:16, minSize: 16 // or simply use size: 16..16
    ...
}

      



This works for strings and will affect schema generation VARCHAR(16)

(e.g. for MySQL)

+9


source







All Articles