Problems with GSON plugin

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|

Problems with GSON plugin

John Moore
The GSON plugin seems to be a good match for my requirements for recording the state of a Policy domain object with its various associations. Unfortunately, my first outing with it has not been a success, and I wonder if I'm just doing something wrong or misunderstanding something. I'm simply calling this in a controller:
 Policy policy = Policy.get(params.id)
  render policy as GSON

I get this error as a result. No sure what the 'identifier' in question is, but it's not coming from my code, I'm sure. Any suggestions?

Cannot get property 'identifier' on null object. Stacktrace follows:
java.lang.NullPointerException: Cannot get property 'identifier' on null object
	at grails.plugin.gson.adapters.GrailsDomainSerializer.eachProperty(GrailsDomainSerializer.groovy:66)
	at grails.plugin.gson.adapters.GrailsDomainSerializer.eachUnvisitedProperty(GrailsDomainSerializer.groovy:51)
	at grails.plugin.gson.adapters.GrailsDomainSerializer.serialize(GrailsDomainSerializer.groovy:27)
	at com.google.gson.TreeTypeAdapter.write(TreeTypeAdapter.java:70)
	at com.google.gson.TreeTypeAdapter.write(TreeTypeAdapter.java:63)
	at com.google.gson.Gson.toJson(Gson.java:586)
	at com.google.gson.Gson.toJsonTree(Gson.java:479)
	at com.google.gson.Gson$3.serialize(Gson.java:140)
	at grails.plugin.gson.adapters.GrailsDomainSerializer$_serialize_closure1.doCall(GrailsDomainSerializer.groovy:44)
	at grails.plugin.gson.adapters.GrailsDomainSerializer$_eachUnvisitedProperty_closure2.doCall(GrailsDomainSerializer.groovy:59)
	at grails.plugin.gson.adapters.GrailsDomainSerializer.eachProperty(GrailsDomainSerializer.groovy:70)
	at grails.plugin.gson.adapters.GrailsDomainSerializer.eachUnvisitedProperty(GrailsDomainSerializer.groovy:51)
	at grails.plugin.gson.adapters.GrailsDomainSerializer.serialize(GrailsDomainSerializer.groovy:27)
	at com.google.gson.TreeTypeAdapter.write(TreeTypeAdapter.java:70)
	at com.google.gson.TreeTypeAdapter.write(TreeTypeAdapter.java:63)
	at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRuntimeTypeWrapper.java:68)
	at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.write(CollectionTypeAdapterFactory.java:96)
	at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.write(CollectionTypeAdapterFactory.java:60)
	at com.google.gson.Gson.toJson(Gson.java:586)
	at com.google.gson.Gson.toJsonTree(Gson.java:479)
	at com.google.gson.Gson$3.serialize(Gson.java:140)
	at grails.plugin.gson.adapters.GrailsDomainSerializer$_serialize_closure1.doCall(GrailsDomainSerializer.groovy:44)
	at grails.plugin.gson.adapters.GrailsDomainSerializer$_eachUnvisitedProperty_closure2.doCall(GrailsDomainSerializer.groovy:56)
	at grails.plugin.gson.adapters.GrailsDomainSerializer.eachProperty(GrailsDomainSerializer.groovy:70)
	at grails.plugin.gson.adapters.GrailsDomainSerializer.eachUnvisitedProperty(GrailsDomainSerializer.groovy:51)
	at grails.plugin.gson.adapters.GrailsDomainSerializer.serialize(GrailsDomainSerializer.groovy:27)
	at com.google.gson.TreeTypeAdapter.write(TreeTypeAdapter.java:70)
	at com.google.gson.TreeTypeAdapter.write(TreeTypeAdapter.java:63)
	at com.google.gson.Gson.toJson(Gson.java:586)
	at com.google.gson.Gson.toJsonTree(Gson.java:479)
	at com.google.gson.Gson$3.serialize(Gson.java:140)
	at grails.plugin.gson.adapters.GrailsDomainSerializer$_serialize_closure1.doCall(GrailsDomainSerializer.groovy:44)
	at grails.plugin.gson.adapters.GrailsDomainSerializer$_eachUnvisitedProperty_closure2.doCall(GrailsDomainSerializer.groovy:56)
	at grails.plugin.gson.adapters.GrailsDomainSerializer.eachProperty(GrailsDomainSerializer.groovy:70)
	at grails.plugin.gson.adapters.GrailsDomainSerializer.eachUnvisitedProperty(GrailsDomainSerializer.groovy:51)
	at grails.plugin.gson.adapters.GrailsDomainSerializer.serialize(GrailsDomainSerializer.groovy:27)
	at com.google.gson.TreeTypeAdapter.write(TreeTypeAdapter.java:70)
	at com.google.gson.TreeTypeAdapter.write(TreeTypeAdapter.java:63)
	at com.google.gson.Gson.toJson(Gson.java:586)
	at com.google.gson.Gson.toJsonTree(Gson.java:479)
	at com.google.gson.Gson$3.serialize(Gson.java:140)
	at grails.plugin.gson.adapters.GrailsDomainSerializer$_serialize_closure1.doCall(GrailsDomainSerializer.groovy:35)
	at grails.plugin.gson.adapters.GrailsDomainSerializer$_eachUnvisitedProperty_closure2.doCall(GrailsDomainSerializer.groovy:59)
	at grails.plugin.gson.adapters.GrailsDomainSerializer.eachProperty(GrailsDomainSerializer.groovy:70)
	at grails.plugin.gson.adapters.GrailsDomainSerializer.eachUnvisitedProperty(GrailsDomainSerializer.groovy:51)
	at grails.plugin.gson.adapters.GrailsDomainSerializer.serialize(GrailsDomainSerializer.groovy:27)
	at com.google.gson.TreeTypeAdapter.write(TreeTypeAdapter.java:70)
	at com.google.gson.TreeTypeAdapter.write(TreeTypeAdapter.java:63)
	at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRuntimeTypeWrapper.java:68)
	at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.write(CollectionTypeAdapterFactory.java:96)
	at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.write(CollectionTypeAdapterFactory.java:60)
	at com.google.gson.Gson.toJson(Gson.java:586)
	at com.google.gson.Gson.toJsonTree(Gson.java:479)
	at com.google.gson.Gson$3.serialize(Gson.java:140)
	at grails.plugin.gson.adapters.GrailsDomainSerializer$_serialize_closure1.doCall(GrailsDomainSerializer.groovy:35)
	at grails.plugin.gson.adapters.GrailsDomainSerializer$_eachUnvisitedProperty_closure2.doCall(GrailsDomainSerializer.groovy:56)
	at grails.plugin.gson.adapters.GrailsDomainSerializer.eachProperty(GrailsDomainSerializer.groovy:70)
	at grails.plugin.gson.adapters.GrailsDomainSerializer.eachUnvisitedProperty(GrailsDomainSerializer.groovy:51)
	at grails.plugin.gson.adapters.GrailsDomainSerializer.serialize(GrailsDomainSerializer.groovy:27)
	at com.google.gson.TreeTypeAdapter.write(TreeTypeAdapter.java:70)
	at com.google.gson.TreeTypeAdapter.write(TreeTypeAdapter.java:63)
	at com.google.gson.Gson.toJson(Gson.java:586)
	at com.google.gson.Gson.toJson(Gson.java:565)
	at com.google.gson.Gson.toJson(Gson.java:540)
	at grails.plugin.gson.converters.GSON.render(GSON.groovy:49)
	at grails.plugin.gson.converters.GSON.render(GSON.groovy:58)
	at grails.plugin.gson.api.ArtefactEnhancer$_enhanceControllers_closure1.doCall(ArtefactEnhancer.groovy:29)
	at com.aire.pei.TestingController.gsontest(TestingController.groovy:166)
	at grails.plugin.cache.web.filter.PageFragmentCachingFilter.doFilter(PageFragmentCachingFilter.java:195)
	at grails.plugin.cache.web.filter.AbstractFilter.doFilter(AbstractFilter.java:63)
	at org.apache.shiro.grails.SavedRequestFilter.doFilter(SavedRequestFilter.java:55)
	at org.apache.shiro.web.servlet.AbstractShiroFilter.executeChain(AbstractShiroFilter.java:449)
	at org.apache.shiro.web.servlet.AbstractShiroFilter$1.call(AbstractShiroFilter.java:365)
	at org.apache.shiro.subject.support.SubjectCallable.doCall(SubjectCallable.java:90)
	at org.apache.shiro.subject.support.SubjectCallable.call(SubjectCallable.java:83)
	at org.apache.shiro.subject.support.DelegatingSubject.execute(DelegatingSubject.java:380)
	at org.apache.shiro.web.servlet.AbstractShiroFilter.doFilterInternal(AbstractShiroFilter.java:362)
	at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
	at java.lang.Thread.run(Thread.java:722)

Reply | Threaded
Open this post in threaded view
|

Re: Problems with GSON plugin

sergiomichels
I think I had this problem too. I'm using the 1.2-SNAPSHOT version to test the last modifications (not ready for production yet).

--
Sérgio Michels


On Tue, Oct 22, 2013 at 3:54 PM, John Moore <[hidden email]> wrote:
The GSON plugin seems to be a good match for my requirements for recording
the state of a Policy domain object with its various associations.
Unfortunately, my first outing with it has not been a success, and I wonder
if I'm just doing something wrong or misunderstanding something. I'm simply
calling this in a controller:


I get this error as a result. No sure what the 'identifier' in question is,
but it's not coming from my code, I'm sure. Any suggestions?





--
View this message in context: http://grails.1312388.n4.nabble.com/Problems-with-GSON-plugin-tp4650668.html
Sent from the Grails - user mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



Reply | Threaded
Open this post in threaded view
|

Re: Problems with GSON plugin

John Moore
Sorry, I should have said that this is version 1.1.3, with Grails 2.2.4.
Reply | Threaded
Open this post in threaded view
|

Re: Problems with GSON plugin

sergiomichels
Could you try 1.2? I think that this bug is fixed.

--
Sérgio Michels


On Tue, Oct 22, 2013 at 6:01 PM, John Moore <[hidden email]> wrote:
Sorry, I should have said that this is version 1.1.3, with Grails 2.2.4.



--
View this message in context: http://grails.1312388.n4.nabble.com/Problems-with-GSON-plugin-tp4650668p4650673.html
Sent from the Grails - user mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



Reply | Threaded
Open this post in threaded view
|

Re: Problems with GSON plugin

John Moore
Well, I tried with 1.2-SNAPSHOT, and didn't hit that error but hit another instead:

Caused by: java.lang.StackOverflowError
	at grails.plugin.gson.adapters.GrailsDomainSerializer.eachUnvisitedProperty(GrailsDomainSerializer.groovy:54)
	at grails.plugin.gson.adapters.GrailsDomainSerializer.serialize(GrailsDomainSerializer.groovy:27)

I'll keep trying.
Reply | Threaded
Open this post in threaded view
|

Re: Problems with GSON plugin

sergiomichels
Oh that's not good. Can you share the domain class definition?

--
Sérgio Michels


On Wed, Oct 23, 2013 at 7:47 AM, John Moore <[hidden email]> wrote:
Well, I tried with 1.2-SNAPSHOT, and didn't hit that error but hit another
instead:



I'll keep trying.




--
View this message in context: http://grails.1312388.n4.nabble.com/Problems-with-GSON-plugin-tp4650668p4650693.html
Sent from the Grails - user mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



Reply | Threaded
Open this post in threaded view
|

Re: Problems with GSON plugin

John Moore
sergiomichels wrote
Oh that's not good. Can you share the domain class definition?
Hm, that's slightly problematic, as there's a business confidentiality issue. It is an insurance application and this is a Policy class, with multiple associations. I suspect the problem is coming from some kind of circular reference, but I thought this was automatically guarded against.

As time is pressing, I'll probably stick with regular JSON for now, and explicitly handle the assocations I'm interested in. If I get some time I'll come back and revisit this, as it looks like a really useful tool.
Reply | Threaded
Open this post in threaded view
|

Re: Problems with GSON plugin

John Moore
I have established that if I set 'grails.converters.gson.resolveProxies=false' in Config.groovy, I don't get the StackOverflowError. Then again, I don't get the associations, which I need. But at least it means that the problem is occurring as a result of handling the associations and tends to support my suspicion that it's some kind of circular reference which is the problem.
Reply | Threaded
Open this post in threaded view
|

Re: Problems with GSON plugin

sergiomichels
@John I think you need to raise a new issue, the plugin should handle circular references. I don't get this exception because I don't need the associations. When I need, I do a join in the query.

--
Sérgio Michels


On Thu, Oct 24, 2013 at 8:32 AM, John Moore <[hidden email]> wrote:
I have established that if I set
'grails.converters.gson.resolveProxies=false' in Config.groovy, I don't get
the StackOverflowError. Then again, I don't get the associations, which I
need. But at least it means that the problem is occurring as a result of
handling the associations and tends to support my suspicion that it's some
kind of circular reference which is the problem.



--
View this message in context: http://grails.1312388.n4.nabble.com/Problems-with-GSON-plugin-tp4650668p4650764.html
Sent from the Grails - user mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



Reply | Threaded
Open this post in threaded view
|

Re: Problems with GSON plugin

AllLangsDevel
I am having a similar issue with 1.1.4 and 2.3.7 is there any resolution on this?
Reply | Threaded
Open this post in threaded view
|

Re: Problems with GSON plugin

AllLangsDevel
This post was updated on .
In reply to this post by sergiomichels
To give a deeper insight when I upgrade to 1.2

java.lang.UnsupportedOperationException: Attempted to serialize java.lang.Class: org.hibernate.proxy.HibernateProxy. Forgot to register a type adapter?

My Code...

render text: objectService.get(Long.parseLong(params.id)), contentType: MediaType.APPLICATION_JSON;

return object.findById(id) as GSON