【发布时间】:2014-06-04 14:48:19
【问题描述】:
我有以下控制器代码:
def save(MyModel model) {
model.save()
}
我正在使用以下方法对其进行测试:
//e.g. 2ff59e55-ee3d-4f66-8bfa-00f355f52c49
def uuid = UUID.randomUUID.toString()
controller.request.contentType = JSON_CONTENT_TYPE
controller.request.method = 'POST'
controller.request.json = "{'uuid': '$uuid', 'description': 'test object', 'count': 1}"
controller.save()
但是,每次我运行测试时,我都会得到,
org.apache.commons.lang.UnhandledException:
org.codehaus.groovy.grails.web.converters.exceptions.ConverterException:
org.codehaus.groovy.grails.web.json.JSONException: Value out of sequence: expected mode to be
OBJECT or ARRAY when writing '{'uuid': '2ff59e55-ee3d-4f66-8bfa-00f355f52c49', 'description': 'test object', 'count': 1}' but was INIT
【问题讨论】:
-
String uuid = UUID.randomUUID().toString()和/{'uuid': "$uuid", 'description': 'test object'}/。使用斜杠字符串以便将"用于 GString。 -
糟糕。我更新了问题以更正
uuid部分;这只是一个错字。我用/.../分隔的 GString 再次测试,但我仍然收到错误。