Compilestatic annotation on an interceptor with data response

102 Views Asked by At

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?

1

There are 1 best solutions below

1
On BEST ANSWER

Use the json builder directly

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

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