Grails @Resource在PUT上抛出GroovyCastException

时间:2013-12-11 19:14:53

标签: grails groovy

我有以下域对象:

package example.rest

import grails.rest.Resource

@Resource(uri="/departments", formats=['json', 'xml'])
class Department {

String displayName
Integer locationId
Boolean showModal

static mapping = {
    id generator: "assigned"
    table "departments"
    version false
}

static constraints = {
    showModal nullable: true
    displayName nullable: true
    locationId nullable: true
}
}

GET的工作正常,但是PUT正在抛出以下异常:

ERROR errors.GrailsExceptionResolver  - GroovyCastException occurred when processing        request: [PUT] /example-rest/departments/21
Cannot cast object 'example.rest.DepartmentController$_update_closure7@6e36bf53' with class 'example.rest.DepartmentController$_update_closure7' to class 'example.rest.DepartmentController'. Stacktrace follows:
org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object 'example.rest.DepartmentController$_update_closure7@6e36bf53' with class 'example.rest.DepartmentController$_update_closure7' to class 'example.rest.DepartmentController'
at grails.plugin.cache.web.filter.PageFragmentCachingFilter.doFilter(PageFragmentCachingFilter.java:200)
at grails.plugin.cache.web.filter.AbstractFilter.doFilter(AbstractFilter.java:63)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:744)

任何帮助都将不胜感激。

2 个答案:

答案 0 :(得分:1)

我在修理http://jira.grails.org/browse/GRAILS-10972时遇到了类似的问题。您的问题应该在Grails 2.3.5中修复(将在本周末发布)。由提交https://github.com/grails/grails-core/commit/d073a93b修复。

确保Config.groovy中的grails.mime.types设置也已更新。必须手动完成。请参阅GRAILS-10973

答案 1 :(得分:0)

您的用例在Grails 2.3.4中运行良好。尝试使用以下PUT请求:

curl -i -X PUT 
        -H "Content-Type: application/json" 
        -d '{"displayName": "Test", "locationId": 1,"showModal": false}' 
        http://localhost:8080/DemoApp/departments/1

假设有一个id为1的部门已经存在。如果有帮助,请指定要查看的请求有效负载。