MongoDB Plugin - view domains as json

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

MongoDB Plugin - view domains as json

nreese
I am using the MongoDB plugin version 1.0.0.GA.  I can successfully save domain objects and view them in Mongo.

Now I am trying to make a controller endpoint that returns a domain as json.  How do you obtain the underlying domain object as json?  For example, If using the java driver natively, I would call myDBObject.toString() and get a json string.  With grails, I call myDomainObject.toString() and get the class name with the oid.

Thanks,

Nathan
Reply | Threaded
Open this post in threaded view
|

Re: MongoDB Plugin - view domains as json

Silvère Lestang
After playing a little with the Groovy Console I think this works:
myDomain.dbo.toString

Silvère

On 28 June 2012 21:53, Reese, Nathan <[hidden email]> wrote:
I am using the MongoDB plugin version 1.0.0.GA.  I can successfully save domain objects and view them in Mongo.

Now I am trying to make a controller endpoint that returns a domain as json.  How do you obtain the underlying domain object as json?  For example, If using the java driver natively, I would call myDBObject.toString() and get a json string.  With grails, I call myDomainObject.toString() and get the class name with the oid.

Thanks,

Nathan

Reply | Threaded
Open this post in threaded view
|

Re: MongoDB Plugin - view domains as json

John Thompson
In reply to this post by nreese
You should be able to treat it like any other object:

render myDOmainObject as JSON
JT
jts-blog.com
Reply | Threaded
Open this post in threaded view
|

Re: MongoDB Plugin - view domains as json

nreese
Thanks for the replies...

myDomain.dbo.toString did exactly what I was looking for, returning the json document as seen in MongoDB

render myDOmainObject as JSON works, but the json object received is not the same as the json document stored in MongoDB.  For instance, my domain class has several members consisting of embedded lists of objects.  For these members, the grails generated json just contains a json object like {"class" : "mySubObject"} instead of the expected array of objects.

Thanks for the help.

Nathan