grails render collection as single json object -


for example have next domain class

user{    string name } 

also have 2 objects of class

new user(name: "john").save() new user(name: "alex").save() 

how should "list" action in usercontroller represent user.list() in json format this

{1: "john", 2: "alex"} 

let me more precise. want this:

usercontroller{    def list = {     render(contenttype: "text/json") {         user.list().each {user->             user.id = user.name         }     } } 

but sadly isn't working.

try array structure,

def list = {     render(contenttype: "text/json") {         results = array {             user.list().each {user->                 result "${user.id}" : "${user.name}"             }         }     } } 

Comments

Popular posts from this blog

jquery - Invalid Assignment Left-Hand Side -

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -