You can do the translation from model to JSON in the filter instead of the action:
controller:
class myController {
def myAction() {
[aThing: 1, anotherThing: [a: 1, b: 2]]
}
}
filter:
class ApiFilters {
def filters = {
xwingFilter(uri:'/api/**') {
after = { model ->
response.setHeader('X-Wing', 'foo')
render model as JSON
return false // prevent normal view from rendering
}
}
}
}