How to ensure consistency of enums in Java serialization?
Posted
by Uri
on Stack Overflow
See other posts from Stack Overflow
or by Uri
Published on 2010-06-16T22:54:38Z
Indexed on
2010/06/16
23:02 UTC
Read the original article
Hit count: 164
When I serialize an object, I can use the serialVersionUID mechanism at the class level to ensure the compatibility of the two types.
However, what happens when I serialize fields of enum values? Is there a way to ensure that the enum type has not been manipulated between serialization and deserialization?
Suppose that I have an enum like OperationResult {SUCCESS, FAIL}, and a field called "result" in an object that is being serialized. How do I ensure, when the object is deserialized, that result is still correct even if someone maliciously reversed the two? (Suppose the enum is declared elsewhere as a static enum)
I am wondering out of curiosity - I use jar-level authentication to prevent manipulation.
© Stack Overflow or respective owner