• Post Reply Bookmark Topic Watch Topic
  • New Topic

Passing non serializable objects on sockets  RSS feed

 
Nirmal Mekala Kumar
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a client server setup using TCP/IP sockets. My server has to respond with an object in response to a client request. The problem is that the object is non-serializable( I still tried and got the notserializable exception). How can I pass non-serializable objects on TCP/IP sockets.
 
Michael Ernest
High Plains Drifter
Sheriff
Posts: 7292
Netbeans IDE VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can't.
 
Nirmal Mekala Kumar
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
so the only way to do it is to hack down the object into serializable object members, send each member on the stream and then build the whole object on the other side ...... manually!!!
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can "serialize" it yourself, say to XML or delimited strings or some format the client and server agree on. If the server is expecting serialized Java objects you might have to copy all the attributes into some new class you make just for the purpose.
 
Nirmal Mekala Kumar
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well James, dont you think that will add a lot of overhead from performance point of view
 
Michael Ernest
High Plains Drifter
Sheriff
Posts: 7292
Netbeans IDE VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Of course it will. But from a performance point of view, the only costs worth talking about are the ones you can avoid.
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Idunno, what's "a lot"? Compared to file IO? A database query? Including a .js file? Parsing XML from a partner system? Any bit of wasted effort in your algorithms or designs could cost you as much.

Yes, there is non-zero overhead to any serialization. Hand coding your own might be more efficient than the reflection in the library. Or not. Try it and see!

Going into old fogey mode ... I worked on a mainframe system where the tech lead agonized and reworked designs tirelessly to cut down on file reads. The difference between 4 reads and 5 could sink a battleship according to him. Then the next system I worked on often did 200 reads, sometimes 2,000. It was just as fast. Sometimes ya just never know what's going to hurt you until it does. Or doesn't.
 
Nirmal Mekala Kumar
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are right James. We can never tell the depth of the ocean from the shore. I have to try out all the possible methods to see what works and what does'nt and why it does not.
thank you for your insights.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!