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