serialize on SWT class

P

PaowZ

Hello there!

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 ?

Thanks a lot :)

V.
 
A

Andrew Thompson

PaowZ wrote:
....
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.
 
P

PaowZ

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...
 
A

Andrew Thompson

PaowZ said:
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/nfto...ference/api/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.
 
A

Andrew Thompson

PaowZ said:
Andrew Thompson a écrit :

...
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.
 
D

Douwe

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
 
R

Red Orchid

Message-ID: said:
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.
 
P

PaowZ

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 :
 
D

Douwe

Red said:
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.


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;
}
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top