Reputation: 35864
I have the following:
render(builder: "json") {
template(message:'hello', dateCreated:'someDate') {
resources {
resource(id: "123")
resource(id: "456")
}
}
}
I'm getting the following in Firebug:
{"template":{"message":"hello","dateCreated":"someDate"}}
I can't figure out why I am not getting the resources collection.
Upvotes: 0
Views: 413
Reputation: 187539
I suspect resource(id: "123")
is being resolved as a call to the g.resource
taglib. Can you try the following instead (or rename resource to something else):
render(builder: "json") {
template(message:'hello', dateCreated:'someDate') {
resources {
'resource'(id: "123")
'resource'(id: "456")
}
}
}
Upvotes: 1
Reputation: 3243
I usually just create a map with the structure that I want and then render it as JSON.
import grails.converters.JSON
def data = [template: [message: 'hello', dateCreated: 'someDate', resources: [[id: "123"], [id:"456"]]]]
render data as JSON
Not sure if that's the exact structure you're looking for but it provides you with
{"template":{"message":"hello","dateCreated":"someDate","resources":[{"id":"123"},{"id":"456"}]}}
You can see an example here:
Upvotes: 1