This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes I/O and Streams and the fly likes serialization problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "serialization problem" Watch "serialization problem" New topic
Author

serialization problem

sam wang
Greenhorn

Joined: Oct 17, 2006
Posts: 3
Dear friends,

I got a problem about java object serialization. the server resides in tomcat, sending the serialized object to the client which locates the same machine, using the same java version(1.5.02). the server side serialization code snippet is as following:

//writting the binary data to a file to compare with client side
try {
FileOutputStream fo = new FileOutputStream(
"/tmp/object.Server");
ObjectOutputStream so = new ObjectOutputStream(fo);
so.writeObject(objectxxx);
so.flush();
so.close();
System.out.println("successful writting OracleCachedRowSet into file /tmp/object.Server");
} catch (Exception e) {
e.printStackTrace();
System.exit(1);
}

I run the same code to serialize the same object through tomcat(as a servlet) and eclipse, but I got different file(different size), the file size generated by tomcat is bigger than the size generated by eclipse. the most important of all, I can't use eclipse to read the object serialized into the file by tomcat, because the serialVersionUID is different. I guess maybe the locale or encoding is different? but I can't find any place to specify or setting encoding or locale.

any hint will be greatly apprieciated!
Sam
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41155
    
  45
Are you sure that the version of class "objectxxx" (and all classes it references directly or indirectly) is the same on both JVMs?


Ping & DNS - my free Android networking tools app
Purushoth Thambu
Ranch Hand

Joined: May 24, 2003
Posts: 425
Neither Tomcat/Eclipse has anything to do with Serialization. If you are 100% confident about the content written by java code under Tomcat and Eclipse then you definitely need to check the version used by Eclipse and Tomcat. Printing out System.getProperty("java.version") and System.getProperty("java.vm.version") to confirm about the versions.

SerialVersionID cannot be different unless you have different versions. Search your classpath to make sure you don't have the 2 different classes.
[ October 20, 2006: Message edited by: Purushothaman Thambu ]
 
jQuery in Action, 2nd edition
 
subject: serialization problem
 
Similar Threads
web service with attachment under java 1.6
Applet-Servlet - objectOutputStream size limit??
About serialization
Socket - StreamCorruptedException
Socket - Stream Corrupted Exception