serialize on SWT class

Discussion in 'Java' started by PaowZ, Dec 9, 2006.

  1. PaowZ

    PaowZ Guest

    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.
    PaowZ, Dec 9, 2006
    #1
    1. Advertising

  2. 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.
    Andrew Thompson, Dec 9, 2006
    #2
    1. Advertising

  3. PaowZ

    PaowZ Guest

    > 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...
    PaowZ, Dec 9, 2006
    #3
  4. PaowZ wrote:
    > > 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/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.
    Andrew Thompson, Dec 9, 2006
    #4
  5. PaowZ

    PaowZ Guest

    Andrew Thompson a écrit :

    > PaowZ wrote:
    > > > 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/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')

    Yes. Those links above are obvious. ^^
    I guess I was not clear enough when talking about that, sorry for my
    english. :)

    regards.
    PaowZ, Dec 9, 2006
    #5
  6. PaowZ wrote:
    > Andrew Thompson a écrit :
    >
    > > PaowZ wrote:
    > > > > 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/api/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.
    Andrew Thompson, Dec 9, 2006
    #6
  7. PaowZ

    Douwe Guest

    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
    Douwe, Dec 9, 2006
    #7
  8. PaowZ

    Red Orchid Guest

    "PaowZ" <> wrote or quoted in
    Message-ID: <>:

    >
    > 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.
    Red Orchid, Dec 9, 2006
    #8
  9. PaowZ

    PaowZ Guest

    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" <> wrote or quoted in
    > Message-ID: <>:
    >
    > >
    > > 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, Dec 10, 2006
    #9
  10. PaowZ

    Douwe Guest

    Red Orchid wrote:

    > 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;
    }
    }
    }
    Douwe, Dec 10, 2006
    #10
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jonah Olsson

    Can I make a class from XML? Serialize?

    Jonah Olsson, Aug 8, 2003, in forum: ASP .Net
    Replies:
    12
    Views:
    501
  2. Craig Buchanan

    serialize class to the viewstate

    Craig Buchanan, Jan 27, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    2,178
  3. Gordz
    Replies:
    3
    Views:
    3,934
    John Oakes
    Jun 7, 2004
  4. =?Utf-8?B?RWFybCBUZWlncm9i?=

    How to NOT serialize a Property of a Class

    =?Utf-8?B?RWFybCBUZWlncm9i?=, Oct 4, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    17,632
    =?Utf-8?B?RWFybCBUZWlncm9i?=
    Oct 5, 2004
  5. Ramon F Herrera

    Where can I download SWT? (SWT homepage)

    Ramon F Herrera, Dec 5, 2007, in forum: Java
    Replies:
    11
    Views:
    4,040
    Ramon F Herrera
    Dec 6, 2007
Loading...

Share This Page