使用JsonBuilder从某个类的实例创建JSON时的StackOverflowError

时间:2015-05-07 06:10:10

标签: grails jsonbuilder

我正在使用JsonBuilder从类的实例创建JSON。 但是我得到了StackOverflowError

我在Grails项目中创建了MyClass的实例。

class MyBook {
    def isbn
    def title
    def author
    def publisher
}

并且将从MyBook的实例创建JSON的代码是

def jsonBuilder = new groovy.json.JsonBuilder()
def myBook = new MyBook(isbn: '0321774094',
                    title: 'Scala for the Impatient',
                    author: 'Cay S. Horstmann',
                    publisher: 'Addison-Wesley Professional')
jsonBuilder(book: myBook)
println("Using an object")
println(jsonBuilder.toPrettyString())

但是我收到了StackOverflowError错误。

堆栈跟踪:

Line | Method
->>  198 | doFilter  in PageFragmentCachingFilter.java
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|     63 | doFilter  in AbstractFilter.java
|   1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
|    615 | run       in java.util.concurrent.ThreadPoolExecutor$Worker
^    745 | run . . . in java.lang.Thread
Caused by ControllerExecutionException: Runtime error executing action
->>  198 | doFilter  in PageFragmentCachingFilter.java
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|     63 | doFilter  in AbstractFilter.java
|   1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
|    615 | run       in java.util.concurrent.ThreadPoolExecutor$Worker
^    745 | run . . . in java.lang.Thread
Caused by InvocationTargetException: null
->>  198 | doFilter  in PageFragmentCachingFilter.java
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|     63 | doFilter  in AbstractFilter.java
|   1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
|    615 | run       in java.util.concurrent.ThreadPoolExecutor$Worker
^    745 | run . . . in java.lang.Thread
Caused by StackOverflowError: null
->>  354 | findClass in java.net.URLClassLoader
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|    425 | loadClass in java.lang.ClassLoader
|    412 | loadClass in     ''
^    358 | loadClass in     ''

来自grails控制台的Stacktrace:

Error |
2015-05-07 11:27:45,974 [http-bio-8080-exec-4] ERROR errors.GrailsExceptionResol
ver  - StackOverflowError occurred when processing request: [GET] /grailsDemo/JS
ONBuilderSlurper/index
Stacktrace follows:
Message: Executing action [index] of controller [com.krixi.JSONBuilderSlurperCon
troller]  caused exception: Runtime error executing action
    Line | Method
->>  198 | doFilter  in grails.plugin.cache.web.filter.PageFragmentCachingFilter

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|     63 | doFilter  in grails.plugin.cache.web.filter.AbstractFilter
|   1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
|    615 | run       in java.util.concurrent.ThreadPoolExecutor$Worker
^    745 | run . . . in java.lang.Thread
Caused by ControllerExecutionException: Runtime error executing action
->>  198 | doFilter  in grails.plugin.cache.web.filter.PageFragmentCachingFilter

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|     63 | doFilter  in grails.plugin.cache.web.filter.AbstractFilter
|   1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
|    615 | run       in java.util.concurrent.ThreadPoolExecutor$Worker
^    745 | run . . . in java.lang.Thread
Caused by InvocationTargetException: null
->>  198 | doFilter  in grails.plugin.cache.web.filter.PageFragmentCachingFilter

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|     63 | doFilter  in grails.plugin.cache.web.filter.AbstractFilter
|   1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
|    615 | run       in java.util.concurrent.ThreadPoolExecutor$Worker
^    745 | run . . . in java.lang.Thread
Caused by StackOverflowError: null
->>  354 | findClass in java.net.URLClassLoader
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|    425 | loadClass in java.lang.ClassLoader
|    412 | loadClass in     ''
^    358 | loadClass in     ''

0 个答案:

没有答案