0
我試圖用這個超好的插件: https://github.com/robfletcher/grails-gson/blob/master/test/apps/gson-test/grails-app/controllers/grails/plugin/gson/test/AlbumController.groovy簡單的Grails GSON插件使用
因爲默認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
}
如何'ToolType'樣子?請看[序列化](https://github.com/robfletcher/grails-gson#serialization)作爲先決條件。 – dmahapatro
好的 - 這是解決方案..我沒有意識到,靜態belongsTo = [tolltype:ToolType];不一樣靜態belongsTo = ToolType; – nycynik
@dmahapatro你想回答?你是對的。 – nycynik