...
> I'm tryin to serialize an SWT object ( Tree class). Run time reports me
> a NotSerializableException though I implement Serializable interface..
On not only the Tree, but any other 'Object's
that it refers to or stores?
> I'm wondering...Is it possible to serialize SWT object ?
Never dealt with it.
Andrew T.
PaowZ - 09 Dec 2006 11:39 GMT
> On not only the Tree, but any other 'Object's
> that it refers to or stores?
actually, I don't know, I'm trying to find out, but it lacks of docs
about it on the internet...
This issue must have been discussed...
Andrew Thompson - 09 Dec 2006 12:11 GMT
> > On not only the Tree, but any other 'Object's
> > that it refers to or stores?
>
> actually, I don't know, I'm trying to find out, but it lacks of docs
> about it on the internet...
<http://help.eclipse.org/help31/nftopic/org.eclipse.platform.doc.isv/reference/ap
i/org/eclipse/swt/widgets/Tree.html>
Description and screenshot..
<http://www.eclipse.org/swt/widgets/>
(All found within 30 seconds of a google
search on 'swt tree javadoc')
> This issue must have been discussed...
(shrugs) ..maybe if you seaqrch this, or more likely
comp.lang.java.gui, or perhaps the SWT specific
forums or mailing list archives.
Andrew T.
PaowZ - 09 Dec 2006 12:39 GMT
Andrew Thompson a ?crit :
> > > On not only the Tree, but any other 'Object's
> > > that it refers to or stores?
[quoted text clipped - 8 lines]
> (All found within 30 seconds of a google
> search on 'swt tree javadoc')
Yes. Those links above are obvious. ^^
I guess I was not clear enough when talking about that, sorry for my
english. :)
regards.
Andrew Thompson - 09 Dec 2006 13:06 GMT
> Andrew Thompson a écrit :
>
[quoted text clipped - 5 lines]
> >
> > <http://help.eclipse.org/help31/nftopic/org.eclipse.platform.doc.isv/reference/ap
i/org/eclipse/swt/widgets/Tree.html>
..
> Yes. Those links above are obvious. ^^
> I guess I was not clear enough when talking about that, sorry for my
> english. :)
Your english seems fine. The question here, is
what 'it' refers to. You state that 'it' lacks docs.
Do you mean serialization?
(I could suggest some further searches,
but searches on 'it' are a little too wide!)
Andrew T.
Hello PaowZ,
the header of the org.eclipse.swt.widgets.Tree sais:
public class Tree extends Composite {
I don't see an 'implements Serializable' there thus it is not
Serializable. I don't know why you would like to serialize a Tree
instance in the first place. Maybe you can work around it ?
Douwe Vos
"PaowZ" <gpaowz@gmail.com> wrote or quoted in
Message-ID: <1165661911.002593.171540@80g2000cwy.googlegroups.com>:
> I'm tryin to serialize an SWT object ( Tree class). Run time reports me
> a NotSerializableException though I implement Serializable interface..
> I'm wondering...Is it possible to serialize SWT object ?
As far as I know, To de/serialize SWT widgets requires different
mechanism from Sun's de/serialization one, because SWT widgets
cannot exist without a parent.
For instance, typical constructors of them are:
Widget w = new Widget(Widget parent, ...);
And the mechanism of Sun's de/serialization is typically:
ObjectInputStream in = ...;
T obj = (T) in.readObject();
That is, the mechanism of Sun's de/serialization do not have
a way to pass "parent" to her.
At the present time, SWT don't support de/serialization of SWT
widgets. Probably, you should implement your own mechanism.
PaowZ - 10 Dec 2006 01:02 GMT
Thank you all, for your replies :)
Well, yes. "it" refered to serialization applied to SWT object.
Indeed, SWT object are not "atomic" structure which enables a
serialization process.
Maybe a SWT serialization process will be implemented in the future.
Anyway, serializing widget such as a tree could allow me to factorize
data into a whole widget instead of serializing many attributes of
given classes..
So the workaround will be a simpler serialization of ArrayList or
stuffs like that :)
regards.
Red Orchid a ?crit :
> "PaowZ" <gpaowz@gmail.com> wrote or quoted in
> Message-ID: <1165661911.002593.171540@80g2000cwy.googlegroups.com>:
[quoted text clipped - 21 lines]
> At the present time, SWT don't support de/serialization of SWT
> widgets. Probably, you should implement your own mechanism.
Douwe - 10 Dec 2006 13:51 GMT
> As far as I know, To de/serialize SWT widgets requires different
> mechanism from Sun's de/serialization one, because SWT widgets
[quoted text clipped - 14 lines]
> At the present time, SWT don't support de/serialization of SWT
> widgets. Probably, you should implement your own mechanism.
This is not true! The serialization process has no problems with these
type of constructors. The parent is just another reference and as long
as this reference is Serializable the serializer has no problems with
it. See test below. More reasonable is that due to the fact an Widget
is bound to a certain Device/Display it would make it hard to serialize
and deserialize these two since they are directly connected to
Hardware.
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.io.Serializable;
public class Test {
public static void main(String[] args) {
new Test();
}
public Test() {
try {
Parent p = new Parent();
ByteArrayOutputStream boas = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(boas);
oos.writeObject(p);
oos.flush();
oos.close();
System.out.println("no Exception occured");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
static class Parent implements Serializable {
public final Child child;
public Parent() {
child = new Child(this);
}
}
static class Child implements Serializable {
public final Parent parent;
public Child(Parent parent) {
this.parent = parent;
}
}
}