Skip to content

Instantly share code, notes, and snippets.

@Noxville
Created July 24, 2016 22:40
Show Gist options
  • Save Noxville/c78559610be12aabc110cc8f9aa35025 to your computer and use it in GitHub Desktop.
Save Noxville/c78559610be12aabc110cc8f9aa35025 to your computer and use it in GitHub Desktop.
RestFilters.groovy
package twopee
import grails.converters.JSON
import groovy.json.JsonOutput
class RestFilters {
def filters = {
all(controller: "(restRanking|restTeam|restLivegames|restModel|restMatch|restEvent|restView|restElo|restGlicko)", action:"") {
before = { }
after = { model ->
String resp = (model?.alreadyJson) ? model.data : (model as JSON)
if (params.prettyprint) {
resp = JsonOutput.prettyPrint(resp.toString())
}
if (params.callback) {
resp = params.callback + "(" + resp + ")"
}
render (contentType: "application/json", text: resp)
return false
}
afterView = { }
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment