在下面的代码我正在构建具有作者和标题的Book.groovy json。我的问题来自Book.groovy我如何删除storesfield ..我已经尝试了以下和渲染后我仍然看到我的商店json回应
def book_custom_list(Integer max) {
println "In book_custom_list"
book_instance.authors.titles.remove('stores')
book_instance.each { e ->
println e.authors.titles
}
render .......
}
Domain Controllers
Book.groovy
class Book {
String name
static hasMany = [authors: Author]
static constraints = {
}
@Override
public String toString() {
name
}
}
Author.groovy
class Author {
String name;
static hasMany = [titles : Title]
static constraints = {
titles cascade: "all-delete-orphan"
}
}
Title.groovy
class Title {
Stores stores
Date dateCreated
}
JSON:
{
"id": 1,
"name": "test",
"authors": [
{
"id": 1,
"name": "sdsd",
"titles": [
{
"id": 7,
"stores": {
"id": 8,
}
"dateCreated": "Sep 25, 2013 12:50:42 PM",
}
]
}]
}
答案 0 :(得分:0)
如果您只想一直包含特定属性,那么您真的想要使用ObjectMarshaller接口。见this article 了解更多详情。
答案 1 :(得分:0)
有很多方法可以在2.3中自定义json渲染。请查看文档:{{3}}