New datatypes JSON and JSONB are not serializable

42 views
Skip to first unread message

Max Kremer

unread,
Jan 18, 2020, 11:54:24 AM1/18/20
to jOOQ User Group
After upgrading from version 3.10 to 3.12 we noticed that we had some problem with the new JSON datatypes. Specifically we were seeing:

java.io.NotSerializableException: org.jooq.JSONB


We we use REDIS caching with all our queries in the form of a MockDataProvider

public class CachedDataProvider implements MockDataProvider

The exception above is throw when we try to serialize the ResultSet


private MockResult[] cacheResult(byte[] key, Result<?> result) {
 
try {
      cache
.set(key, serializeResult(result), helper.getTTL());
 
} catch (Exception e) {
      logger
.error("Failed to cache SQL result", e);
 
}
 
return mockResult(result);
 
}



private byte[] serializeResult(Result<?> object) {
 
try (ByteArrayOutputStream byteStream = new ByteArrayOutputStream()) {
       
ObjectOutputStream objectStream = new ObjectOutputStream(byteStream);  
       objectStream
.writeObject(object);
       objectStream
.flush();
 
return byteStream.toByteArray();
 
} catch (IOException ex) {
 logger
.error("Error while serializing Result", ex);
 
}
 
return null;
 
}

Enter code here...


Trying to serialize the Result using objectStream.writeObject(object);  is where the exception is thrown.

Any advice on how to handle this? The only solution that comes to mind is extending JOOQ's JSONB class and implementing serializable.







Max Kremer

unread,
Jan 18, 2020, 12:22:35 PM1/18/20
to jOOQ User Group
Just realised the JSONB class is final so it can not be extended :(

Knut Wannheden

unread,
Jan 20, 2020, 3:12:52 AM1/20/20
to jOOQ User Group
Hi Max,

Thank you for your message. Yes, I believe this is an oversight. I have reported a corresponding issue: https://github.com/jOOQ/jOOQ/issues/9747.

Once the issue has been fixed (and backported to the 3.12 branch) you can build jOOQ from sources and use that until the next patch release is available.

Best regards,
Knut

Lukas Eder

unread,
Jan 20, 2020, 3:22:36 AM1/20/20
to jOOQ User Group
Agreed, an oversight.

--
You received this message because you are subscribed to the Google Groups "jOOQ User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jooq-user+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jooq-user/6dc43c52-62cc-444d-84a6-cb6af0622558%40googlegroups.com.

Max Kremer

unread,
Jan 20, 2020, 9:08:49 AM1/20/20
to jOOQ User Group
Lukas and Knut, thank you for confirming! I will keep an eye on this github issue.

Thanks for your help and for building an amazing product!


On Monday, January 20, 2020 at 2:22:36 AM UTC-6, Lukas Eder wrote:
Agreed, an oversight.

To unsubscribe from this group and stop receiving emails from it, send an email to jooq...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages