0

我正在尝试使用这个超级好的插件: https ://github.com/robfletcher/grails-gson/blob/master/test/apps/gson-test/grails-app/controllers/grails/plugin/gson/test/专辑控制器.groovy

因为默认的 GRAILS JSON 不会展开相关项。

但是,当我尝试它时,它失败了。

现在,当我这样做时,它可以工作:

def levelJson() {

    render ToolType.list(params) as JSON
}

这失败了:

def levelJson() {

    render ToolType.list(params) as GSON
}

错误:

ERROR errors.GrailsExceptionResolver  - UnsupportedOperationException occurred when processing request: [GET] /authtools/toolType/levelJson
Attempted to serialize java.lang.Class: org.hibernate.proxy.HibernateProxy. Forgot to register a type adapter?. Stacktrace follows:
Message: Attempted to serialize java.lang.Class: org.hibernate.proxy.HibernateProxy. Forgot to register a type adapter?

课程:

class Artist {
    String name
    static hasMany = [albums: Album]
}

class Album {
    String title
    static belongsTo = Artist
}
4

1 回答 1

0

dmahapatro 指出的解决方案是修改数据类 belongsTo

之前(不工作):

class Album {
    String title
    static belongsTo = Artist
}

之后(工作):

class Album {
    String title
    static belongsTo = [artist: Artist]
}
于 2013-06-27T17:25:09.923 回答