views:

68

answers:

1

Hi all, I'm trying to convert a domain class into JSON.

def converter = null
try{
  converter = events as JSON
} catch(e) {
  log.error "error during conversion to JSON"
  log.error e
}
return converter.toString()

I always get this error:

    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

This is the domain class: http://www.copypastecode.com/31527 The only problem I can see is the 'context' reference. But even if I set to 'null', I still get the stack overflow.

My converter is not propagating circular references. I'd like to debug it and find out which property is causing the problem, but no luck so far. Any hints?

Cheers

+1  A: 

Sorry, would prefer to add this as a comment, but do not have the rep to add comments yet.

In your domain class it sounds like there are several classes that extend off this one, how are you populating the 'events' object? Since you say the context is set to null and that is the only relationship that's defined directly, a list of unintended subclasses in your results is one way that springs to mind for how you could get into such a deep recursion scenario.

To work around the immediate problem so you can do some debugging, have you tried calling:

converter.setRenderDomainClassRelations(false) 
proflux
That's what I get:Exception Message: No signature of method: static grails.converters.JSON.setRenderDomainClassRelations() is applicable for argument types: (java.lang.Boolean) values: [false]
Mulone