Generate JSON With JSON-Views
Looks like a bug to me. The only way to achieve what you are looking for is to use the views as shown below. Also note the usage of collection
instead of model
. I would file a bug with the sample app I used to test below.
Note the usage of template as a fully qualified name
basket/item
. This is the defect.
//index.gsonimport com.example.Basketmodel { Iterable<Basket> basketItems}json { baskets g.render(template: 'basket', collection: basketItems, var: 'basket')}
//_basket.gsonimport com.example.Basketmodel { Basket basket}json { items g.render(template: "basket/item", collection: basket.items, var: 'item')}
//_item.gsonimport com.example.BasketItemmodel { BasketItem item}json g.render(item)//or if id is not required in response/*json { name item.name}*/