1

In Grails when using CommandObjects or DomainClass how can I restrict a constraint of an inherited property?

Say I have a parent class with non-null property payload:

abstract class TextContentCommand extends ContentCommand {

    String payload

    static constraints = {            
        payload nullable: false
    }

In the subclass I'd like to make the property stricter and set the max length:

class FacebookTextContentCommand extends TextContentCommand {

    public static final int LENGTH_MAX = 4

    static constraints = {
        importFrom TextContentCommand
        payload maxSize: LENGTH_MAX
    }
}

This way is not working and when a longer string is provided the validation passes. My knowledge of Grails is very superficial. How can I restrict the inherited properties?

Amio.io
  • 20,677
  • 15
  • 82
  • 117

1 Answers1

0

The constant LENGTH_MAX was causing the problem. Providing the value directly makes the validation work again.

class FacebookTextContentCommand extends TextContentCommand {

    static constraints = {
        importFrom TextContentCommand
        payload maxSize: 4
    }
}
Amio.io
  • 20,677
  • 15
  • 82
  • 117