Reputation: 156
what's the simplest way to respond in json using grails? E.G. the following doesn't work.
boolean a = false
render a as JSON
Upvotes: 2
Views: 1970
Reputation: 360
render(contentType: "application/json"){
message{
a.each{val->
value(val)
}
}
}
Upvotes: 0
Reputation: 51915
Grails requires that the target of the JSON converter be something that can be represented as a collection of name/value pairs or an ordered list. So an object such as a map or list would work. And non-primitive objects should also work, since they can be represented as a map of properties.
In your case, something like this would work:
def a = []
a << false
render a as JSON
Upvotes: 2
Reputation: 120168
directly from the documentation, something like
render(contentType: "text/json") {
hello = "world"
}
Upvotes: 0
Reputation: 1356
Use grails.converter.JSON and you can build the json map directly
Upvotes: -1