Object serialization.

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,
I'm new to .net. I need some info on serialization.

What is serialization? Why do we need it? Why objects need to be serialized
if they need to be stored in session or viewstate?
 
Hi,

Serialization is the process of transforming an object into a stream for
transmission so that they can be recreated later.

We need serialization because we need to pass objects across application
domains or tiers to recreate it there along with the object's state
information.

Objects stored in Session or ViewState needs to be serialized because we
want to the object to persist its state across postbacks, and HTTP is a
stateless protocol, so...

For more insight, see this article in MSDN
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndotnet/html/objserializ.asp

Let me know if you need anything else.

Thanks
Joyjit
 
Serialization is necessary in viewstate (albeit it looks encrypted) because
HTML can only show text, not a binary object. It could conceivably use a
binary description of an object encoded to text, but that encoding is yet
another protocol, so XML is easier from a decision-making standpoint.
I'll give you another example of using serialization, as I really don't mess
with the viewstate and dont' care about the format of my session vars: I
work on an app that displays grids of data for reports but also displays
complex hierarchies of relationships. For the former, I just use automatic
databinding, and that's that, as tables are perfectly suited for that kind
of data. However, for the hierarchical data, my intent is to pull various
related records into a hierarchical structure (my object). However, SQL
Server doesn't return CLR objects, so the DB and my app communicate with
text. Because of that, when the app gets the data, it can either get a
bunch of DB records and build an object from that, but that is tying DB
schema into the app. Instead, I just have the DB query return the data in
XML (in other words, as a serialized object). All my code has to do to
access that object now is to merely deserialize it.
 
Back
Top