1

I am working with a Spring JPA database and am attempting to migrate old Serializable objects to Externalible ones (for future data restructures, etc).

Example Structure

- Entity

(Encryption Convertor)
Serializble Field

My goal is to take this existing Serializble object and migrate it to an Externalizble version. Somehow working around Serializable incompatible with Externalizable

Thank you for all the help

  • I think you’ll need to use two different classes. Java Serialization is not a great choice for storing objects to a database. This is one example of why. – Tim Moore Jul 21 '23 at 23:19
  • @TimMoore Unfortunately I did not follow my due diligence and do some more research into the shortcomings of Java Serialization when I was originally implementing this system. Would that be the only way? Even using two different classes, how would I perform the swap? – SwordOfSouls Jul 21 '23 at 23:21
  • 1
    I would recommend migrating away from Java Serialization entirely, rather than changing Serializable to Externalizable. Please see https://stackoverflow.com/a/818093/29470 – Tim Moore Jul 21 '23 at 23:24
  • @TimMoore I have done some research this time and do believe that the Java Externalizable solution fits perfectly my needs. Even using two different classes as you suggested, how would I perform the swap? – SwordOfSouls Jul 21 '23 at 23:26
  • I think it’s possible to implement your `readExternal` method in a way that can read previously serialized data, but if the format is different than the one produced by `writeExternal`, it will be up to you to write the logic to determine which format is in the stream and handle the differences. – Tim Moore Jul 22 '23 at 00:01
  • If you want to use two different classes, you can leave the original Serializable class mostly alone to retain the automatic deserialization logic, but implement `readResolve` to return an instance of the new Externalizable class with data copied as needed. – Tim Moore Jul 22 '23 at 00:02

1 Answers1

1

Seemed to have found a relatively simple fix without double classes.

Attain the plugin JRebel (I got a trial). Upon Init store a list of all of the entries in your database. Update the classes to implement Externalizable (seeing as you already have the infrastructure in place). Wipe your database, and add back all of the elements in your prior list. (The HotReload will have updated them)