0

I am creating JSON from an instance of class using JsonBuilder. But I am getting StackOverflowError.

I created instance of MyClass, in Grails project.

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

and the code which would create JSON from an instance of MyBook is

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())

But I am getting StackOverflowError error.

Stacktrace:

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     ''

Stacktrace from grails console:

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     ''
Burt Beckwith
  • 75,342
  • 5
  • 143
  • 156
Pankaj Shinde
  • 3,361
  • 2
  • 35
  • 44
  • somewhere in that trace should be code/packages visisble from you. please provide this part and also correlate the line numbers with your code. more often than not, SO indicates an infinte loop. – cfrick May 07 '15 at 06:20
  • Please check updated Stacktrace from grails console – Pankaj Shinde May 07 '15 at 06:28
  • After the latest edit you example works well. – Opal May 07 '15 at 08:59
  • Not working. Thats my original question. I just forgot to mention `def jsonBuilder = new groovy.json.JsonBuilder()` in my question, which was updated. – Pankaj Shinde May 07 '15 at 09:08

0 Answers0