10.10.4 Rendering Domain Classes with JSON Views

Typically your model may involve one or many domain instances. JSON views provide a render method for rendering these.

For example given the following domain class:

  1. class Book {
  2. String title
  3. }

And the following template:

  1. model {
  2. Book book
  3. }
  4. json g.render(book)

The resulting output is:

  1. {id:1, title:"The Stand"}

You can customize the rendering by including or excluding properties:

  1. json g.render(book, [includes:['title']])

Or by providing a closure to add additional JSON output:

  1. json g.render(book) {
  2. pages 1000
  3. }