title: JSON rendering fails for domain objects in ControllerUnitTestCase
body: <p>I'm writing a unit test for a Grails controller that renders a domain class to a JSON response:</p>
  
  <pre><code>class MyController {
      def find = {
          def domainInst = MyDomainClass.get(params.id)
          render ([data: domainInst] as JSON)
      }
  }
  </code></pre>
  
  <p>The unit test extends ControllerUnitTestCase and provides a mock for the domain object:</p>
  
  <pre><code>class MyControllerTests extends ControllerUnitTestCase {
      @Before
      void setUp() {
          super.setUp()
          mockDomain(MyDomainClass, [new MyDomainClass(id: 7)])
      }
  
      @Test
      void testFind() {
          def inst = MyDomainClass.get(7)
          controller.params.id = inst.id
          controller.find()
          assert(controller.response.json.data.id == inst.id)
      }
  </code></pre>
  
  <p>This all seems to be working nicely except for the JSON rendering, which spits out a nasty stack trace:</p>
  
  <pre><code>| Failure:  testFind(MyControllerTests)
  |  org.apache.commons.lang.UnhandledException: 
          org.codehaus.groovy.grails.web.converters.exceptions.ConverterException: Error converting Bean with class MyDomainClass
          Caused by: org.codehaus.groovy.grails.web.converters.exceptions.ConverterException: Error converting Bean with class MyDomainClass
  at grails.converters.JSON.value(JSON.java:199)
  at grails.converters.JSON.convertAnother(JSON.java:162)
  at grails.converters.JSON.value(JSON.java:199)
  at grails.converters.JSON.render(JSON.java:134)
  ... 5 more
          Caused by: java.lang.reflect.InvocationTargetException
  ... 9 more
          Caused by: groovy.lang.MissingMethodException: No signature of method: MyDomainClass.isAttached() is applicable for argument types: () values: []
          Possible solutions: isAttached(), attach()
  ... 9 more
  </code></pre>
  
  <p>Changing the return to a Map instead of a domain class works:</p>
  
  <pre><code>render ([data: [id: domainInst.id]] as JSON)
  </code></pre>
  
  <p>What's causing the JSON marshaller to die on the domain class? It works in a normal environment, but not in the mock test environment. Is there a way to make this test work?</p>