Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Java serialization. Field changes value  RSS feed

 
Siobhan Chom
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Genius thanks! I thought using flush would be enough. but reset works very well
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!