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

Upgrading to 4.5.0 causes class cast exception #72

Closed davidbairdala closed 9 years ago

davidbairdala commented 9 years ago

I have a project that defines a domain object that has a Map property mapped to JsonMapType.

class MyDomainClass implements Serializable {

    Map customFields = [:]

    static mapping = {
        customFields type: JsonMapType
    }
}

Under version 4.4.0 the following works:

 def instance = MyDomainClass.get(params.id)

WIth version 4.5.0 the same code yields:

org.postgresql.util.PGobject cannot be cast to java.lang.String. Stacktrace follows:
Message: org.postgresql.util.PGobject cannot be cast to java.lang.String
    Line | Method
->>   49 | nullSafeGet in net.kaleidos.hibernate.usertype.JsonMapType

I am running against Postgres 9.3. Not sure if I'm doing something wrong, or if this is a bug introduced with 4.5.0.

Cheers, David.

ilopmar commented 9 years ago

I'll try to reproduce it and create a test for it and fix it. I need to dig a little bit to see what change introduced in the last version broke that.

ilopmar commented 9 years ago

I can't reproduce it from a test but I've been able to reproduce it from run-app. The change was introduced in #65 to fix this issue #66.

I'm doing some test to fix this.

eamon316 commented 9 years ago

Just came across this today. Looks as if the following will fix

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

as noted in [#66]

Is there a release planned to fix?

Thanks for all the effort +1 on the plugin

ilopmar commented 9 years ago

I'll try to publish a new version during this week.

ilopmar commented 9 years ago

I finally found the time to publish a new version. Fixed in 4.6.0 :-)

gregopet commented 8 years ago

I tried this and got exceptions when the field was null; currently using

        PGobject jsonObject = (PGobject)rs.getObject(names[0]);
        if (jsonObject != null) {
            return gson.fromJson(jsonObject.getValue(), userType);
        } else {
            return null;
        }
ilopmar commented 8 years ago

That's was fixed in #77 and released in 4.6.1. Could you please try with that version?

gregopet commented 8 years ago

I'm using the Grails 3 branch, I guess it wasn't ported to that branch yet?

ilopmar commented 8 years ago

Yes, you're right. The last changes have not been applied to the 3.x branch. You need to wait until next week...