• Post Reply Bookmark Topic Watch Topic
  • New Topic

How deep does Serialization go?

 
Leslie Chaim
Ranch Hand
Posts: 336
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using the Command pattern to communicate between my Client/Server processes.
It seems that my entire Object, that is the Command with the encapsulated data, does not arrive at the server
I have written a helper method that prints out the contents of a Command Object:

And I have inserted at Client side and at the Server side:

On the Client side, I see the Data output is like this:

For table 'ALLMANAGERS' Here is the Data
Row 0 :1085957022|00001|4147|BM|
For table 'AMENDMENT' Here is the Data
No Data Available
For table 'BEARER_REGISTERED' Here is the Data
Row 0 :1085957022|00001|-|
For table 'BIDDERS' Here is the Data
No Data Available
For table 'BOOKMANAGERS' Here is the Data
Row 0 :1085957022|00001|4147|

On the Sever site, this is what shows

For table 'ALLMANAGERS' Here is the Data
No Data Available
For table 'AMENDMENT' Here is the Data
No Data Available
For table 'BEARER_REGISTERED' Here is the Data
No Data Available
For table 'BIDDERS' Here is the Data
No Data Available
For table 'BOOKMANAGERS' Here is the Data
No Data Available


I am Sooo close, please help.
Thank you,
Leslie
[ November 26, 2002: Message edited by: Leslie Chaim ]
 
Leslie Chaim
Ranch Hand
Posts: 336
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Google is great!
I found This article
I tried it and it does the trick!!!
Simply changing my client code from:

to:

Does it!
Now is that really needed? It sounds like I am using double serialization :roll: And what about efficiency
 
Bogdan Parau
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try oos.reset(); before write any object.
take a look onthis article:
http://developer.java.sun.com/servlet/PrintPageServlet?url=http%3A//developer.java.sun.com/developer/technicalArticles/ALT/sockets/
and specialy on this part
"When working with object serialization it is important to keep in mind
that the ObjectOutputStream maintains a hashtable mapping the
objects written into the stream to a handle. When an object is written to
the stream for the first time, its contents will be copied to the stream.
Subsequent writes, however, result in a handle to the object being written
to the stream. This may lead to a couple of problems:
If an object is written to the stream then modified and written a
second time, the modifications will not be noticed when the stream is
deserialized. Again, the reason is that subsequent writes results in the
handle being written but the modified object is not copied into the
stream. To solve this problem, call the
ObjectOutputStream.reset method that discards the memory of
having sent an object so subsequent writes copy the object into the
stream.
An OutOfMemoryError may be thrown after writing a
large number of objects into the ObjectOutputStream. The
reason for this is that the hashtable maintains references to objects that
might otherwise be unreachable by an application. This problem can be
solved simply by calling the ObjectOutputStream.reset method
to reset the object/handle table to its initial state. After this call,
all previously written objects will be eligible for garbage collection.
The reset method resets the stream state to be the same as if
it had just been constructed. This method may not be called while objects
are being serialized. Inappropriate invocations of this method result in
an IOException."
 
Leslie Chaim
Ranch Hand
Posts: 336
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks so much Bogdan This is really nice that your very first post to the Java ranch is to help someone else.
I inserted the call to reset() and it works!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!