我正在尝试将域类转换为 JSON。
def converter = null
try{
converter = events as JSON
} catch(e) {
log.error "error during conversion to JSON"
log.error e
}
return converter.toString()
我总是收到这个错误:
org.codehaus.groovy.grails.web.servlet.mvc.exceptions.ControllerExecutionException: Executing action [findEvents] of controller
[com.geoadapta.geodata.DataAccessJsonController] caused exception:
java.lang.StackOverflowError
at java.lang.Thread.run(Thread.java:619)
Caused by: org.codehaus.groovy.runtime.InvokerInvocationException: java.lang.StackOverflowError
... 1 more
Caused by: java.lang.StackOverflowError
at org.codehaus.groovy.util.AbstractConcurrentMap.getOrPut(AbstractConcurrentMap.java:20)
at grails.converters.JSON.value(JSON.java:188)
at grails.converters.JSON.convertAnother(JSON.java:160)
at grails.converters.JSON.value(JSON.java:192)
// hundreds of times
at grails.converters.JSON.value(JSON.java:192)
at grails.converters.JSON.convertAnother(JSON.java:160)
at grails.converters.JSON.value(JSON.java:192)
at grails.converters.JSON.convertAnother(JSON.java:160)
at grails.converters.JSON.value(JSON.java:192)
at grails.converters.JSON.convertAnother(JSON.java:160)
at grails.converters.JSON.value(JSON.java:192)
at grails.converters.JSON.convertAnother(JSON.java:160)
at grails.converters.JSON.value(JSON.java:192)
at grails.converters.JSON.convertAnother(JSON.java:160)
at grails.converters.JSON.value(JSON.java:192)
2010-06-23 16:21:28,390 [http-8080-1] DEBUG [/GeoAdaptaApp].[grails] - Disabling the response for futher output
这是域类:http://www.copypastecode.com/31527
我能看到的唯一问题是“上下文”引用。但即使我设置为'null',我仍然会得到堆栈溢出。
我的转换器没有传播循环引用。
我想调试它并找出导致问题的属性,但到目前为止还没有运气。
有什么提示吗?
干杯
最佳答案
抱歉,希望将此添加为评论,但还没有代表添加评论。
在您的域类中,听起来有几个类扩展了这个类,您如何填充“事件”对象?由于您说上下文设置为 null 并且这是直接定义的唯一关系,因此结果中的意外子类列表是您想到如何进入如此深度递归场景的一种方式。
要解决眼前的问题以便您可以进行一些调试,您是否尝试过调用:
converter.setRenderDomainClassRelations(false)
关于grails - JSON 转换器 - 堆栈溢出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3103141/