The name may be misleading. I really want to know the closing name in the controller. But Groovy closures are always anonymous, so there is no name for the closure itself. But the closure is assigned to the variable, and I wonder if I can get the name of this variable. Perhaps an example will help. In the Grails controller, imagine that I have the following:
def get_data = {
Map results = [ 'errorCode' = -1, 'method' : 'get_data' ]
...
render results as JSON
}
In Map, called the result, there is an element called the "method" that I want to give the name of this closure (or the variable holding the closure to be more precise). Is it possible? The idea here is that I want to summarize the result map and want to automatically populate an element called the "method". Instinctively, it seems that this should be possible, but I have not found similar use cases that illustrate how to do this. Any help is greatly appreciated.
source
share