title: Grails 3 gson views and domain class template
body: <p>I'm playing around with Grails 3, specifically REST Api support features.</p>
  
  <p>One of the new features (coming from 2.5.5) is the new gson views.</p>
  
  <p>I'm trying to follow the <a href="http://views.grails.org/latest/#_rendering_domain_classes" rel="nofollow noreferrer">documentation</a>, but my template seems to be ignored.</p>
  
  <p>I've made my sample project available on <a href="https://github.com/townsfolk/grails3_test" rel="nofollow noreferrer">github</a>, but the important bits are here:</p>
  
  <p>My <code>UrlMapping</code>:</p>
  
  <pre><code>"/books"(resources: "book")
  </code></pre>
  
  <p>My <code>Book</code> domain class:</p>
  
  <pre><code>class Book {
  
     String title
  
     static constraints = {
        title(blank: false)
     }
  }
  </code></pre>
  
  <p>From my <code>BookController</code>:</p>
  
  <pre><code>def show(Book book) {
      respond new Book(id: 1, title: "Foo bar")
  }
  </code></pre>
  
  <p>My <code>show.gson</code>:</p>
  
  <pre><code>model {
     Book book
  }
  json g.render(book)
  </code></pre>
  
  <p>Finally, my <code>book/_book.gson</code>:</p>
  
  <pre><code>json {
     title "Book Template"
  }
  </code></pre>
  
  <p>What I see in the browser with this setup is:</p>
  
  <pre><code>{"title":"Foo bar"}
  </code></pre>
  
  <p>I went looking online for some examples and found <a href="https://causecode.com/blog/46/json-views-getting-started-with-grails-31-and-intellij" rel="nofollow noreferrer">this one</a></p>
  
  <p>Which leads me to believe that Grails should ignore or bypass my <code>show.gson</code> and just render my <code>_book.gson</code>, but that isn't happening. I tried deleting my <code>show.gson</code>, but then I got a blank page.</p>
  
  <p>The <a href="http://views.grails.org/latest/#_rendering_domain_classes" rel="nofollow noreferrer">Grails documentation</a> leads me to believe that my <code>show.gson</code> should render my <code>_book.gson</code> template, but that isn't happening either.</p>
  
  <p>I've tried cleaning and re-running, but I get the same result.</p>
  
  <p>I was able to get it to work using a fully qualified template name:</p>
  
  <p>"Fixed" <code>show.gson</code>:</p>
  
  <pre><code>model {
     Book book
  }
  json g.render(template: "/book/book", model: [book: book])
  </code></pre>
  
  <p>Workable, but not ideal, and not what's in the docs.</p>
  
  <p>I'm not sure what I'm doing wrong here, I must be missing something.</p>