What I want: to force my code [to] change serialVersionUID
automatically ... when I change internal structure of these classes.
No you don't. You want to keep the serialVersionUID
the same forever, and to restrict the internal changes to what can be handled automatically by Serialization, for which you need to consult the Versioning chapter of the Object Serialization Specification. Changing the serialVersionUID
on every class change is an urban myth which unfortunately has been far too widely propagated and accepted.
And your proposed solution won't work either. 'Skipping deserialization instances of old versions of [a] class' isn't a solution to anything. Serialization will already have rejected it with an exception if the serialVersionUIDs
don't agree. Anything you do after that is already too late.
This is sounding like an XY problem. You want to do X, you think Y is the answer, so you ask about Y, when you should be asking about X. For the correct solution see above.