IntelliJ Java IDE
The moose likes I/O and Streams and the fly likes Java serialization. Field changes value Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Reply Bookmark "Java serialization. Field changes value" Watch "Java serialization. Field changes value" New topic
Author

Java serialization. Field changes value

Siobhan Chom
Greenhorn

Joined: Jan 19, 2012
Posts: 4
0 down vote favorite
share [fb] share [tw]


I have the following problem. I can set the transaction state to be either "start, end or ongoing". I set this, then serialise my Transaction object over to the server, who retrieves it. Works like a charm the first time (when the transaction is in start mode), but then when I resend the object, this time in "ongoing" mode, the server continues to see it in "start" mode. I've tested the code at the line before the serialization, and the line after the deserialization, and this is definitely where the problem is. Any help would be very much appreciated. The relevant code snippets are as follows:

serialization


deserialization


and the Transaction class:


Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 3144
If you resend the same object over the same stream, the object itself is not sent, just a reference to the original one sent (which obviously will still have the original value). This is done to save bandwidth on network serialization and make files of serialized objects smaller. If you want the stream to actually resend the object, there's a method to make it forget what it has sent so far. I think it's reset(), but check the docs to be sure.
Siobhan Chom
Greenhorn

Joined: Jan 19, 2012
Posts: 4
Genius thanks! I thought using flush would be enough. but reset works very well
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 3144
Siobhan Chom wrote:Genius thanks! I thought using flush would be enough. but reset works very well


Calling flush() just tells the stream to send any data it's buffering to the other end.

Glad you got it sorted out! Welcome to the Ranch!
 
 
subject: Java serialization. Field changes value
 
Threads others viewed
serializable problem
serialization: object casting doubt
a program on wrapper classes
How the objects are constructed at the time of de-serialization?
Serialization: Non serialized class issue
MyEclipse, The Clear Choice

cast iron skillet 49er

more from paul wheaton's glorious empire of web junk: cast iron skillet diatomaceous earth rocket mass heater sepp holzer raised garden beds raising chickens lawn care CFL flea control missoula heat permaculture