title: Using custom JSON marshaller in Grails with deep option
body: <p>Is it possible to use custom JSON marshallers using the deep option of JSON?</p>
  
  <p>I've been trying some things and without the deep option, my custom marshallers are working fine. But when I add JSON.use('deep') my custom marshallers are never called...</p>
  
  <p>Is there something else that I need to do?</p>
  
  <p>What I have tried thus far (all this in Bootstrap and also with and without priority param (values 1 and 999999)). Also I've tried putting the JSON.use('deep') call at the beginning and the end with the same results.</p>
  
  <p>OPTION 1</p>
  
  <pre><code>JSON.use("deep") {
      JSON.registerObjectMarshaller(new UserMarshaller(),999999)
      JSON.registerObjectMarshaller(new TeamMarshaller(),999999)
      JSON.registerObjectMarshaller(new LevelMarshaller(),999999)
      JSON.registerObjectMarshaller(new BehaviourMarshaller(),999999)
      JSON.registerObjectMarshaller(new AchievementMarshaller(),999999)
      JSON.registerObjectMarshaller(new PercentageAchievementMarshaller(),999999)
      JSON.registerObjectMarshaller(new IntervalMarshaller(),999999)
      JSON.registerObjectMarshaller(new MissionMarshaller(),999999)
      JSON.registerObjectMarshaller(new ActivityMarshaller(),999999)
      JSON.registerObjectMarshaller(new RecentActivityMarshaller(),999999)
      JSON.registerObjectMarshaller(new ProfileMarshaller(),999999)
      JSON.registerObjectMarshaller(new StatusMarshaller(),999999)
      JSON.registerObjectMarshaller(ObjectId){ObjectId oid-&gt;
          return oid.toString()
      }
  }
  
  JSON.use('deep')
  </code></pre>
  
  <p>OPTION 2</p>
  
  <pre><code>JSON.registerObjectMarshaller(new UserMarshaller(),999999)
  JSON.registerObjectMarshaller(new TeamMarshaller(),999999)
  JSON.registerObjectMarshaller(new LevelMarshaller(),999999)
  JSON.registerObjectMarshaller(new BehaviourMarshaller(),999999)
  JSON.registerObjectMarshaller(new AchievementMarshaller(),999999)
  JSON.registerObjectMarshaller(new PercentageAchievementMarshaller(),999999)
  JSON.registerObjectMarshaller(new IntervalMarshaller(),999999)
  JSON.registerObjectMarshaller(new MissionMarshaller(),999999)
  JSON.registerObjectMarshaller(new ActivityMarshaller(),999999)
  JSON.registerObjectMarshaller(new RecentActivityMarshaller(),999999)
  JSON.registerObjectMarshaller(new ProfileMarshaller(),999999)
  JSON.registerObjectMarshaller(new StatusMarshaller(),999999)
  JSON.registerObjectMarshaller(ObjectId){ObjectId oid-&gt;
      return oid.toString()
  }
  
      JSON.use('deep')
  </code></pre>
  
  <p>And also tried the Config option, but has no effect, the deep conversion is not triggered...</p>
  
  <p>UPDATE: An example
  One mission has many achievements and I want to retrieve a mission and its achievements</p>
  
  <pre><code>class Mission {
  
      /** Identificador */
      ObjectId id
      /** Nombre */
      String  name
      /** Indica si la misión está o no activa */
      boolean active = true
  
      List&lt;AchievementBase&gt; achievements = []
  
      static hasMany = [achievements:AchievementBasen]
  }
  
  class AchievementBase {
      /** Identificador */
      ObjectId id
      /** Nombre del logro */
      String name
      /** Valor booleano para indicar si el logro está o no activo */
      boolean active = true
      /** Valor booleano para indicar si el logro está o no visible */
      boolean hidden = false
  
  }
  </code></pre>
  
  <p>And this is one example of the marshaller I was writing</p>
  
  <pre><code>class MissionMarshaller implements ObjectMarshaller&lt;JSON&gt;{  
      @Override
      public boolean supports(Object object) {
          object instanceof Mission
      }
  
      @Override
      public void marshalObject(Object object, JSON converter)
              throws ConverterException {
          JSONWriter writer = converter.getWriter()
          writer.object()
          writer.key('id').value(object.id)
          .key("name").value(object.name)
          .key('achievements').value(object.achievements)
          writer.endObject()
      }
  
  }
  
  class AchievementMarshaller implements ObjectMarshaller&lt;JSON&gt;{
  
      @Override
      public boolean supports(Object object) {
          object instanceof Achievement
      }
  
      @Override
      public void marshalObject(Object object, JSON converter)
              throws ConverterException {
          JSONWriter writer = converter.getWriter()
          writer.object()
          writer.key('id').value(object.id)
              .key("name").value(object.name)
          writer.endObject()
      }
  
  }
  </code></pre>