dcsimg
Customizing the format in which objects are serialized.
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Jeevan_Sunkersett
Posted On:   Monday, April 14, 2003 05:35 AM

Hi, I am doing Socket communication, where-in the client gets an object and builds a fixed format string from it (using string concatenation and the objects getter methods) Passes the data (in String format) to the server over a socket connection. The Server at its end has to parse the String and reply accordingly. The passing of data between client & server is mandatory-ily as a String (in fixed format such as, first 3 chars=id, Next 10=First-Name, Next 2=Middle-Initial and so on) If I can implement my own serialization, where by I will write the string data received by server to file And then read it into an object (de-serialize) I would not have to worry about developing a parsing a   More>>

Hi,

I am doing Socket communication, where-in the client gets an object and builds a fixed format string from it (using string concatenation and the objects getter methods)



Passes the data (in String format) to the server over a socket connection.



The Server at its end has to parse the String and reply accordingly.



The passing of data between client & server is mandatory-ily as a String (in fixed format such as, first 3 chars=id, Next 10=First-Name, Next 2=Middle-Initial and so on)



If I can implement my own serialization, where by I will write the string data received by server to file
And then read it into an object (de-serialize) I would not have to worry about developing a parsing algorithm for the fixed format data.



Is it possible to control serlization of objects to achieve this ? Any pointers/URL's (to maybe already working code) will be appreciated.



rgds

g1

   <<Less

Re: Customizing the format in which objects are serialized.

Posted By:   Iuga_Marin  
Posted On:   Thursday, May 15, 2003 09:25 AM

Yes, you can have control over the serialization of objects.

Declare your class as implementing java.io.Externalizable
and implement the readExternal and writeExternal methods.

Here is the JavaDoc for Externalizable:


http://java.sun.com/j2se/1.4.1/docs/api/java/io/Externalizable.html


and here is a link to a good tutorial:


http://developer.java.sun.com/developer/TechTips/2000/tt0425.html#tip1



Regards,
Marin.
About | Sitemap | Contact