Easy way to render JSON with HTTP status code in Grails

grails, groovy

Solution

If you use a converter parameter to render then you cannot specify any other parameter such as status like you normally would when using gsp views. You can however set the response status prior to calling render:

response.status = 500
render([error: 'an error occurred'] as JSON)

Problem

Is there a shorthand way to do this without explicit `"text/json"` designation? ``` def remoteError = { render( status: 500, contentType: "text/json"){ error( exception: "a remote exception occurred") } } ``` I tried using `as JSON`...no content is returned but the status code is correct... ``` render( status: 500, exception: params.exception) as JSON ```

Original source