I am trying to add a dynamic property to each instance of a class and then convert a list of such objects to json. Refer to the example below
class Author{
String name
static hasMany=[books:Book]
}
class Book{
String title
static belongsTo=[author:Author]
}
my controller
class AuthorController{
def listAuthors={
def authorsList=Author.list()
def details=['address':'xyz', phone:'123']
authorList.each{
it.metaClass.getDetails={->details}
}
render authorsList as JSON
}
}
now i want this dynamically added "details" property to also get rendered as JSON. please help