Search code examples
grailsinterceptorcompile-static

Compilestatic annotation on an interceptor with data response


In an interceptor I have this code:

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

It is not possible to add the @CompileStatic annotation on this interceptor, as the msg variable isn't declared. Is there any way to write this in a "compilestatic" friendly way?


Solution

  • Use the json builder directly

    def json = new JsonBuilder()
    json.call([msg: 'Message to show'])
    
    render(text: json.toString(), contentType: 'text/json')