title: Full JSON render of object with nested object
body: <p>I have a grails application with mongodb plugin.</p>
  
  <p>All my domain objects are:</p>
  
  <pre><code>class Person {
    ObjectId id
    String name
  }
  </code></pre>
  
  <p>and</p>
  
  <pre><code>class Like {
    ObjectId id
    Person from
    Person to
    Date createdAt
  }
  </code></pre>
  
  <p>My controller should give a full data according to some <code>Like</code> by id:</p>
  
  <pre><code>class MyController {
    def like() {
      def like = Like.findById(new ObjectId("someIdHere"));
      render(like as grails.converters.JSON)
    }
  }
  </code></pre>
  
  <p>I wish to receive a full JSON-object of like:</p>
  
  <pre><code>{
    "class":"Like",
    "id":{
      "class":"org.bson.types.ObjectId",
      "inc":1483542456,
      "machine":805594765,
      "new":false,
      "time":1340363115000,
      "timeSecond":1340363115
    },
    "createdAt":"2012-06-22T11:05:15Z",
    "from":{
      "class":"Person",
      "id":{ ... },
      "name":"Some name here"
    },
    "to":{
      "class":"Person",
      "id":{ ... },
      "name":"Some name here"
    }
  }
  </code></pre>
  
  <p>but I've receive first-level properties of object:</p>
  
  <pre><code>{
    "class":"Like",
    "id":{
      "class":"org.bson.types.ObjectId",
      "inc":1483542456,
      "machine":805594765,
      "new":false,
      "time":1340363115000,
      "timeSecond":1340363115
    },
    "createdAt":"2012-06-22T11:05:15Z",
    "from":{
      "class":"Person",
      "id":"4fd31d453004dc0f010aca51"
    },
    "to":{
      "class":"Person",
      "id":"4fd31d463004dc0f010aca89"
    }
  }
  </code></pre>
  
  <p>My question is: is there any way to construct full (with referenced objects) JSON of mongo db (DBObject) data object? I've found out this <a href="https://stackoverflow.com/a/5543915">solution with JSONBuiled</a> with escaped fields 'class', metaClass' and 'dbo'. But I think it can be done with Expando classes but I cann't find the right way...</p>
  
  <p>Thanks any way,
  Maksim</p>