Um.... actually, you can't do that; if you try to Serialize a
non-Serializable-implementing class, you'll get a NotSerializableException.

This example, for example, will fail to Serialize:

import java.io.*;

class Value
{
    public int value = 12;
}

public class NotSerial
    implements Serializable
{
    public Value v = new Value();

    public static void main(String[] args)
        throws Exception
    {
        if (args[0] != null)
        {
            // Write
            NotSerial ns = new NotSerial();

            ObjectOutputStream oos =
                new ObjectOutputStream(
                    new FileOutputStream("NotSerial.ser"));

            oos.writeObject(ns);
        }
        else
        {
            // Read
            ObjectInputStream ois =
                new ObjectInputStream(
                    new FileInputStream("NotSerial.ser"));

            NotSerial ns = (NotSerial)ois.readObject();
        }
    }
}

Running "java NotSerial a" results in:

E:\Test>java NotSerial a
Exception in thread "main" java.io.NotSerializableException: Value
        at java.io.ObjectOutputStream.outputObject(Compiled Code)
        at
java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:342)
        at java.io.ObjectOutputStream.outputClassFields(Compiled Code)
        at
java.io.ObjectOutputStream.defaultWriteObject(ObjectOutputStream.java
:453)
        at java.io.ObjectOutputStream.outputObject(Compiled Code)
        at
java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:342)
        at NotSerial.main(NotSerial.java:25)

E:\Test>

I'm not sure what you're trying to say when you claim that ">yeah, you can
implement wrapper classes that implement Serializable in order >to stores
things >that aren't persistent, persistent.", but asking Serialization to
serialize an object that contains a non-Serializable class fails. Moreover,
you are flat wrong when you state, ">Serialising causes objects inside them
to be stored in some form regardless >as to whether they are >Serializable
or not.", as the above example demonstrates.

Can you elucidate what you intended?

Ted Neward
Patterns/C++/Java/CORBA/EJB/COM-DCOM spoken here
http://www.javageeks.com/~tneward
 "I don't even speak for myself; my wife won't let me." --Me

-----Original Message-----
From: Andy Bailey <[EMAIL PROTECTED]>
To: [EMAIL PROTECTED] <[EMAIL PROTECTED]>
Date: Monday, July 26, 1999 10:09 AM
Subject: Re: Swing Applet and Servlet communication via JDBC


>> I am new in Java domain but the need of the project forced me to adopt
it.
>I am
>> developing a web-based workflow application using swing applets and
>servlets. In
>> Swing to populate UI elemnts like JTable and JTree it is required to
>implement
>> data models classes. My idea is to initiate corresponding servlet from
>DataModel
>> classes of Swing UI elements and the servlet execute the query via JDBC
>and pass
>> the JDBC RecordSet object to calling DataModel class, where RecordSet
>object can
>> be used to implement all functions of DataModel.
>>
>> My limited research reveled me that it is not possible to pass RecordSet
>object
>> b/c that does not implement Serializable interface but one can pass
>RecordSet
>> within Vector object.
>>
>> Kindly suggests me the best approach or comments on the above-mentioned
>> approach.
>> Thanks in advance.
>> Regds.
>> Muhammad Azam
>>
>Hi,
>
>yeah, you can implement wrapper classes that implement Serializable in
order
>to stores things
>that aren't persistent, persistent.
>
>A vector carries a lot of baggage with them so you could do the following
>
>public class PersistentResultSet implements Serializable {
>
>     Object stored = null;
>
>     public PersistentResultSet(ResultSet stored) {
>         this.stored = stored;
>     }
>
>    public ResultSet getResultSet() {
>        return (ResultSet)stored;
>    }
>}
>
>This is a simple persistent placeholder for a record set.
>
>(note that I mimic the Vector ability to hold any object here but singly,
>this is not needed).
>
>Serialising causes objects inside them to be stored in some form regardless
>as to whether they are
>Serializable or not.
>
>Beware though, a ResultSet is a very dynamic object. It can be trapped
>between transaction begins
>commits and is dependent on its Connection and the Statement that produced
>it. There is no guarantee
>that you will have anything of use when it comes to unpickling it. Much
>better to grab the data, store it
>in a DataModel and store that instead (or shove it up to your applet).
>
>Hope that helps
>
>Andy Bailey
>
>___________________________________________________________________________
>To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
>of the message "signoff SERVLET-INTEREST".
>
>Archives: http://archives.java.sun.com/archives/servlet-interest.html
>Resources: http://java.sun.com/products/servlet/external-resources.html
>LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to