当我尝试使用GSON和Grails Rest配置文件应用程序渲染字符串列表时,
java.lang.ClassCastException: _info_app_name__schemaImporter_index_gson$_run_closure1 cannot be cast to grails.plugin.json.builder.StreamingJsonBuilder$StreamingJsonDelegate
我的控制器类如下
class SchemaImporterController {
static responseFormats = ['json']
def index() {
def data = [:]
data.stringList = [
'One',
'Two',
'Three',
'Four
] as ArrayList<String>
return data
}
}
我的GSON索引视图如下
model{
List<String> stringList
}
json{
informationList stringList.each { String str ->
singleEntry str
}
}
在声明模型变量(如列表字符串列表,数组列表)时,我还尝试了其他变体
但是,每次执行此操作时,它都会返回相同的错误。知道为什么吗?这里只需要注意的是,当我渲染其他域类时,它可以正常工作。
我找到了罪魁祸首。在遍历列表时,我正在使用它们。我删除了它,并使其如下所示成为GSON视图,它开始正常工作。
model{
List<String> stringList
}
json{
informationList stringList, { String str ->
singleEntry str
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句