Fun times with JSON Rendering
I spent the last couple of hours on my pet project working with a specific issue. After moving it’s hosting to Google AppEngine the classes have meta data stored in them. I’m not allowed to reflect over the meta data (not sure I want to either). So JSON rendering has to be done on something other than the domain class.
This is the same Issue I posted about in a previous post, about rendering lists as JSON.
Now I’m rendering a single instance of a domain class. Now for the fun part. I can’t render JSON with the following statement.
render [ id: user.id, name: user.name, email: user.email, password: user.password ] as JSON
render ( id: user.id, name: user.name, email: user.email, password: user.password ) as JSON
I suspect that the above code will be transformed to a parameter listing for the render as JSON code.
After allot of trying I finally figure out that this works:
def userJson = [ id: user.id, name: user.name, email: user.email, password: user.password] render userJson as JSON
Fun! I can render the variable holding the map, but not the map directly.