kaleidos / grails-postgresql-extensions

Grails plugin to use postgresql native elements such as arrays, hstores,...
Apache License 2.0
78 stars 62 forks source link

Use rs.getObject() to deserialize jsonb data #65

Closed zlegein closed 9 years ago

zlegein commented 9 years ago

When storing data into the database using jsonbMapType we use

st.setObject(index, gson.toJson(value, userType), Types.OTHER);

which will serializes the data into the database. I would propose we change the get to use

String jsonString = rs.getObject(names[0])

This will deserialize the data before parsing. I realize this works with postgreSQL, but the problem arises when running test using H2, which a lot of grails projects rely on. H2 will not deserialize the data before attempting to parse it.

ilopmar commented 9 years ago

Fixed in #66

ilopmar commented 9 years ago

@zlegein we have a regresion with this fix. Please check #72.

I've change to

String jsonString = ((PGobject)rs.getObject(names[0])).getValue();

But I think it won't work with H2.

So, in order to understand this. Are you running some integration tests against H2 instead of Postgresql? Are you using the JsonMapType against H2 and it's working?

Joshua-Brent-Collins commented 9 years ago

Hello, I have an abstract domain class that I think i'm seeing a similar issue with. All i'm doing is using a dynamic finder to search for an entries in my db and I keep getting these errors :

Argument is not an array. Stacktrace follows:
Message: Argument is not an array
    Line | Method
->>  109 | nullSafeGet   in net.kaleidos.hibernate.usertype.ArrayType
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|    105 | methodMissing in org.grails.datastore.gorm.GormStaticApi
|     90 | show . . . .  in com.experience.admin.site.fan.FanController
|    198 | doFilter      in grails.plugin.cache.web.filter.PageFragmentCachingFilter
|     63 | doFilter . .  in grails.plugin.cache.web.filter.AbstractFilter
|     53 | doFilter      in grails.plugin.springsecurity.web.filter.GrailsAnonymousAuthenticationFilter
|     49 | doFilter . .  in grails.plugin.springsecurity.web.authentication.RequestHolderAuthenticationFilter
|     82 | doFilter      in grails.plugin.springsecurity.web.authentication.logout.MutableLogoutFilter
|   1142 | runWorker . . in java.util.concurrent.ThreadPoolExecutor
|    617 | run           in java.util.concurrent.ThreadPoolExecutor$Worker
^    745 | run . . . . . in java.lang.Thread

I'm using version postgresql-extensions:4.4.0 and grails 2.5.0 any suggestions would be appreciated. Thanks!

Note: I changed my version to 4.5.0 and it seems to be fixed i'll leave this comment here for anyone else seeing this issue.

ilopmar commented 9 years ago

@Joshua-Brent-Collins could you please open a new issue with an example of what you're trying to do? At least post the domain class and the dynamic finder you're trying to execute.