如何在不定义内部模板的情况下使用 Grails JSON 视图?

How to use Grails JSON view without defining internal templates?

我有一个域 class:

class Business {
    String name
    String description
}

我有以下 JSON 个模板:

index.gson:为对象列表

生成JSON

_business.gson: 为业务对象

生成JSON

index.gson

import server.Business
model {
    Iterable businessList
}
json {
    result tmpl.business(businessList ?: [])
}

_business.gson

model {
        Business business
}
json {
    id business.id
    name business.name
} 

如何在不使用 _business.gson 模板的情况下为业务对象生成 JSON?

我想采用一种只有 index.gson 并手动渲染内部对象的方法。

import server.Business
model {
    Iterable businessList
}

json {
    **WHAT SHOULD I ADD HERE?**
}

json(businessList.toList()) {
    **I also noticed that I can use this syntax, BUT WHAT SHOULD I ADD HERE?**
}

你可以在 json 闭包中做任何你想做的事。

json(businessList.toList()) { Business business ->
    id business.id
    name business.name
    description business.description
}