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;
}
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.