aspose file tools
The moose likes Servlets and the fly likes java.io.Serializable Problem Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Servlets
Reply Bookmark "java.io.Serializable Problem" Watch "java.io.Serializable Problem" New topic
Author

java.io.Serializable Problem

ch praveen
Ranch Hand

Joined: Mar 08, 2004
Posts: 67
Hello Friends,
Iam programming a muticlient, chatserver based on appletservlet communication. When I tried to pass Enumeration object to ObjectOutputStream's, writeObject(Object obj) method I got an exception at runtime (not at compile time) stating that Enumeration doen't implements Serializable interface. Then I created a class, SerializableWrapper that implements Serializable interface and wraps any Object. Eventhough I got the same exception, then I have implemented Hastable to make things better.
Now my question is, if we build a class that implements Serializable interface and wraps datatypes such as String and so on, it is working well with writeObject() method. Moreever if this class doesn't implement Serializable interface, an exception is thrown at compiletime itself but if same class wraps, Enumeration object, it is not working with writeObject() method and error is not thrown at compiletime.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12327
    
    1
If I understand your problem - the compiler can't possibly figure out if all the objects that could be referred to in your class can be serialized. It can only be determined when you actually try to serialize based on the actual objects encountered.
Bill


Java Resources at www.wbrogden.com
Sajee Joseph
Ranch Hand

Joined: Jan 17, 2001
Posts: 200
Thus for the above discussion is it correct to assume that
1. There is nothing that a Servlet constructor cant achieve that an init() can achieve ( init without the config object).
2. Thus usage of init() and constructor are 'either-or' situations.
Correct me if im wrong
Regards,
Sajee
Panagiotis Varlagas
Ranch Hand

Joined: Nov 27, 2000
Posts: 233
It's the wrong thread Sajee
Originally posted by Sajee Joseph:
Thus for the above discussion is it correct to assume that
1. There is nothing that a Servlet constructor cant achieve that an init() can achieve ( init without the config object).
2. Thus usage of init() and constructor are 'either-or' situations.
Correct me if im wrong
Regards,
Sajee
Panagiotis Varlagas
Ranch Hand

Joined: Nov 27, 2000
Posts: 233
ch praveen,

You may want to check this out:
http://java.sun.com/docs/books/tutorial/essential/io/providing.html
Also (important point): When you want to serialize an object, since a object, in general, contains references (pointers) to other objects, you have to ensure that everything in the object graph is serializable
(or otherwise mark it as transient).
Hope this helps,
Panagiotis.
[ March 15, 2004: Message edited by: Panagiotis Varlagas ]
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: java.io.Serializable Problem
 
Similar Threads
writeObject()
regarding marker interfaces
Use of Marker Interface
About Serializable
Serializable in inheritance