Re: Achieving serialization of non-serializable objects
On Sep 16, 6:51 am, "Qu0ll" <Qu0llSixF...@gmail.com> wrote:
I need to serialize some Java2D objects of classes such as Shape,
GlyphVector and Composite, none of which implements or extends Serializab=
le.
Is it possible somehow? If I can achieve the same thing where I can
reconstruct those objects on the other side of a network connection witho=
ut
strictly doing serialization then that will be fine. I thought about
extracting the "data" from each object and serializing that but some of t=
hat
information is either internal or not always available.
Any ideas? Perhaps it cannot be done.
Think carefully about what serialization does. It does not, contary
to the illusion the API maintains, "store objects" - given an object,
serialization produces a description of the object that can be
reconstituted into another object with the same properties. The
description is flat data.
With that in mind, you should already have some idea how to
"serialize", for example, Shape: what properties (completely) describe
a Shape instance? Can you map a Shape to a serializable object that
carries those properties? And, once you have those properties, can
you constitute a Shape from them?
Granted, writing serializable proxies for every Java2D class you want
to serialize is tedious. It's possible someone's already written one;
you'd have to look around a bit on google. It may also be more
sensible to serialize your own, app-specific classes which just happen
to be able to produce Java2D objects as needed at runtime. What you
can't (usefully) do is serialize the existing Java2D objects blindly,
either using ObjectOutputStream or reflection - that they're not
Serializable suggests that they may have internal state that's not
appropriate for serialization.
-o