1

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.

Anonymous
  • 696
  • 8
  • 21
  • I'd like to argue that it should be left alone, that post is six years old and newer versions of Java may have new approaches to the problem. – Anonymous Aug 29 '18 at 19:19
  • 1
    Nothing has changed with regard to serialization since the introduction of enums in Java 5 afaik. The duplicate is still relevant. However as the answers on that question are vague and incomplete, I think it might be worth to leave this question open and hope it attracts better answers. – Mark Rotteveel Aug 31 '18 at 16:48

0 Answers0