I think that in principle some code somewhere must make a field-by-field
copy for you. If you don't want to write explicit copy/conversion code for
each pair to call from readResolve/writeResolve, you could write a converter
using reflection. If you have an interface defining the core part (using,
say, Java Bean patterns), you could probably even auto-create the core
object as a Proxy object with an underlying Map to carry the actual data.
Hmm, now, why didn't I think of that earlier ...
I did it with explicit copies. It was not that many fields. But I
discovered something annoying about java in process.
The thing I want to distribute has a
MiniA object with a MiniB reference.
The thing I want to work with has an
A object with a B reference.
A is a subclass of MiniA and B is a subclass of MiniB.
To strip an A object for export I must create a new MiniA object with
just the fields it needs with a reference to MiniB object with just
the fields it needs.
OK, fine, so there is no simple way to turn a A back to a MiniA.
But I have to declare the reference inside MiniA to MiniB as type
MiniB.
Then A inherits that. It inherits a MiniB reference. It wants a B
reference!!
Obviously, I can store B references in the MiniB variable, but every
time I fish them out of an A object I have to cast them back to type
B.
It seems to me, it should be somehow possible to add EXTRA restriction
on what a field can be in a subclassed object.
In a similar way, when I override a method, the return type should be
permitted to be more restrictive than the type returned in the base
class.