0

我有一个域类:

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?**
}
4

1 回答 1

1

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

json(businessList.toList()) { Business business ->
    id business.id
    name business.name
    description business.description
}
于 2017-06-19T14:36:58.013 回答