【发布时间】:2012-07-09 16:10:18
【问题描述】:
我正在尝试将 grails 参数映射解析为 Json 字符串,然后返回参数映射。 (用于保存违反约束的 html 表单条目)
只要参数映射中没有 hasMany 关系,一切都很好。
我正在使用
fc.parameter = params as JSON
将参数保存为 JSON 字符串。
稍后我尝试重建参数映射并使用它创建一个新的域对象:
new Foo(JSON.parse(fc.parameter))
仅使用 1:1 关系(状态)一切都很好。
[states:2, listSize:50, name:TestFilter]
但是当我尝试使用多选值(状态)重建参数映射时
[states:[1,2], listSize:50, name:TestFilter]
我收到了这个 IllegalStateException:
Failed to convert property value of type org.codehaus.groovy.grails.web.json.JSONArray to required type java.util.Set for property states; nested exception is java.lang.IllegalStateException: Cannot convert value of type [java.lang.String] to required type [de.gotosec.approve.State] for property states[0]: no matching editors or conversion strategy found
我尝试使用它,但没有成功:
JSON.use("deep") {
new Foo(JSON.parse(fc.parameter))
}
【问题讨论】:
标签: json parsing grails parameters