带有数据响应的拦截器上的编译静态注释

Compilestatic annotation on an interceptor with data response

在拦截器中我有这样的代码:

render(contentType: 'text/json') {
  msg 'Message to show'
}

无法在此拦截器上添加 @CompileStatic 注释,因为未声明 [​​=12=] 变量。 有什么办法可以用 "compilestatic" 友好的方式来写这个吗?

直接使用json生成器

def json = new JsonBuilder()
json.call([msg: 'Message to show'])

render(text: json.toString(), contentType: 'text/json')