Serialization…not just for breakfast

So what the hell is serialization?  This word gets toss around quite a bit by developers, but I’ve yet to hear one actually be able to explain what it is.  So let me edumacate you.

Objects are build by instantiating classes.  Objects have properties and methods.  Methods are shared by all instances of the class; properties are NOT shared.  So the only thing that makes an object different from other objects of the same class is its properties.  Clear?  Good.

Now, I need to work with a web service, let’s say on Server A.  Server A has a web service where it will query a database and return, let’s say, a customer invoice.  It will give me the data as an object.  Sorta.  Let’s keep going.

So I talk to Server A and I say “Hey, give me this customer invoice, here’s the ID”.  Server A responds “Here it is…”, then a bunch of XML text comes back.  What the frig?

The XML text is what we call serialized; it is a list of the properties of the Invoice objects along with the specific values.  So if my Invoice object has a ClientName property, I would see <ClientName>Joe Blow</ClientName>.

So what do I do on my side?  Well hell, I deserialize it!  My class must implement the ISerializable interface, which has a deserialize method.  I can implement this method which will take the values and assign them to the appropriate properties of the object that I have built on my side; reflection is a great tool here.

And what if I need to update the invoice?  Why, I serialize it and send it back to the web service.

Serializing is fun and is the basis for all web services.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: