Reputation: 12205
I have a domain object with a property called date:
class Item implements Comparable{
Date date
}
How can I access that date doing something like:
Item.list().each{
Date d = it.get("date")
}
I know that I could do Date d = it.date
but I want to be able to generically pick a property from my domain object and access it without using .property.
Upvotes: 1
Views: 113
Reputation: 437
This should also work:
String propertyName = 'date'
Item.list().each {
Date d = it."$propertyName"
}
Upvotes: 3
Reputation: 7619
Try this..,.
Item.list().each {
Date d = it.properties.get("date")
}
or
Item.list().each {
Date d = it.getProperty("date")
}
Upvotes: 2