【发布时间】:2015-05-16 01:59:57
【问题描述】:
我正在寻找一种在 grails (2.4.5) 中将对象根添加到我的 JSON 的方法。通常,Grails 会像这样呈现 JSON 对象列表:
[{"id":1,"title":"Catan","description":"Catan"}]
但我需要它看起来像:
{"games": [{"id":1,"title":"Catan","description":"Catan"}]}
理想情况下,我想调整我创建的自定义编组器来执行此操作,但我不知道如何去做:
class GameMarshaller {
void register() {
JSON.registerObjectMarshaller(Game) { Game node ->
return [
id : node.id,
title : node.title,
description : node.description
]
}
}
}
【问题讨论】:
标签: json grails marshalling