I’m working on some dynamic filtering, and have this:
class Filterable {
def statusId
def secondaryFilterable
}
...
def filter = new Filter(validIds: [1], fieldName: 'statusId')
...
class Filter {
def validIds = [] as Set
def fieldName
private boolean containsFieldValue(input) {
def fieldValue = input."${fieldName}"
return fieldValue in validIds
}
}
Which works just fine for one property. However, now I need to filter by the secondary filterable – something like
def filter = new Filter(validIds: [1], fieldName: 'secondaryFilterable.statusId')
Which throws a groovy.lang.MissingPropertyException. Any advice?
Quoted properties assume a dot is part of the property name.
A simple solution would be:
This will recursively look up the field value using dot notation for child properties.
I put up a working example here on the Groovy web console.