I have a static integer value in a class that I am trying to serialize.
We have our own writeObject what writes the integer out each time the
object is written.
This works.
However, I would like to only write the integer out once.
I can detect when I am on the last object during a write, but can't
during a read...
except through readResolve.
Would it work to call readObject from readResolve to get that integer?
Other ideas?
-MIke
Thomas Hawtin - 05 Oct 2006 16:56 GMT
> I have a static integer value in a class that I am trying to serialize.
>
[quoted text clipped - 9 lines]
>
> Would it work to call readObject from readResolve to get that integer?
I'm not exactly sure what you are after.
If you are trying to serialise a static field, I think the answer is to
rework your code into something sensible.
If you want a serialised object to stand in for a reference to a
particular static field value, then readResolve seems sensible (I'm not
exactly sure on the rules for static typing on that). I don't know why
you would want to manipulate the stream from readResolve.
Tom Hawtin
Robert Klemme - 05 Oct 2006 20:28 GMT
> I have a static integer value in a class that I am trying to serialize.
There is no point in serializing static data as it will always be there
(always meaning as long as the class is loaded).
> Other ideas?
Change your code to remove the necessity to serialize static content.
Kind regards
robert