New datatypes JSON and JSONB are not serializable

42 vues
Accéder directement au premier message non lu

Max Kremer

non lue,
18 janv. 2020, 11:54:2418/01/2020
à 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

non lue,
18 janv. 2020, 12:22:3518/01/2020
à jOOQ User Group
Just realised the JSONB class is final so it can not be extended :(

Knut Wannheden

non lue,
20 janv. 2020, 03:12:5220/01/2020
à 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

non lue,
20 janv. 2020, 03:22:3620/01/2020
à 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

non lue,
20 janv. 2020, 09:08:4920/01/2020
à 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.
Répondre à tous
Répondre à l'auteur
Transférer
0 nouveau message