I'm working on deserializing large files that need to be able to be supported by future versions of the software in the future that have different attributes. I've used readObject() in many places to add versioning support, however there's one thing I'm not quite sure how to fix.
java.io.InvalidObjectException: enum constant ENUM_NAME does not exist in class
How do you get around this? How do I add a readObject()-esque function to the enum to allow versioning of that enum (I.E. returning null for the enum or etc) when loading that particular enum fails?
From what I understand, you can't simply add a readObject() to enums since Java handles their deserialization differently. Or am I mistaken? It's hard to google the subject and find my specific problem. I really need a way to handle the versioning of enums.
Thank you in advance for your help.
EDIT: I'm aware that there's a similar question here: Handling deserialization of enum values that no longer exist
I'd like to leave the question open for discussion since that post was made in 2012 (and it's subsequent answer was made in 2014) and newer Java versions may have new solutions to the problem. Thank you.