2013-10-15 41 views
1

在下面的代碼中,我正在構建Book.groovy json,它具有作者和標題。我的問題來自Book.groovy我如何刪除storesfield ..我嘗試了以下內容,並在使我仍然看到專賣店在我的JSON響應從對象/ 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

如果你想只包含特定屬性的時候,你真的要使用的ObjectMarshaller接口。有關更多詳情,請參閱this article