IT Community - Software Programming, Web Development and Technical Support

Serialization and Deserialization

This is a discussion on Serialization and Deserialization within the VB.NET Programming forums, part of the Software Development category; Hui Guys can anyone tell me What do you mean by Serialization and Deserialization and it's use....


Go Back   IT Community - Software Programming, Web Development and Technical Support > Software Development > VB.NET Programming

Register FAQ Members List Calendar Mark Forums Read
  #1  
Old 08-01-2007, 05:19 AM
vigneshgets vigneshgets is offline
D-Web Genius
 
Join Date: Mar 2007
Posts: 904
vigneshgets is on a distinguished road
Wink Serialization and Deserialization

Hui Guys can anyone tell me What do you mean by Serialization and Deserialization and it's use.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2  
Old 08-01-2007, 05:27 AM
kingmaker kingmaker is offline
D-Web Genius
 
Join Date: Jun 2007
Posts: 881
kingmaker is on a distinguished road
Send a message via MSN to kingmaker
Thumbs up Re: Serialization and Deserialization

A more elegant solution is to use the serialization and deserialization features of XML. A serialization is a series of data values, usually text, which represents an object. It contains the object's public and private variables, and any other information needed to completely describe the object. For example, suppose a Student object contains LastName and FirstName variables, and an array of test scores. The XML serialization of a Student object might look like this:

<Student>
<LastName>Stephens</LastName>
<FirstName>Rod</FirstName>
<TestScore TestNumber="1" Score="80" />
<TestScore TestNumber="2" Score="92" />
<TestScore TestNumber="3" Score="87" />
<TestScore TestNumber="4" Score="94" />
</Student>

Building a serialization for a class is simple enough following roughly the same steps you would take to save the object in a database, as described in the previous section. The class just concatenates the object's variable values into a string. Later, it could parse the serialization string to restore the object. To make an XML serialization, the class includes the proper tags.

This method works, but has some of the same drawbacks as the previous method. In particular, if you modify the class, you need to modify the code that reads and writes the serialization.


xml_serializer As New XmlSerializer(GetType(Person)


xml_serializer.Serialize(string_writer, customer)



Here's what an actual serialization produced by the XmlSerializer might look like:

<?xml version="1.0" encoding="utf-16"?>
<Person xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<LastName>Stephens</LastName>
<FirstName>Rod</FirstName>
<EmailAddress>RodStephens@vb-helper.com</EmailAddress>
</Person>


  1. Class SOAP Deserialization
  2. Object Serialization
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3  
Old 08-20-2007, 11:41 PM
S.Vinothkumar S.Vinothkumar is offline
D-Web Genius
 
Join Date: May 2007
Posts: 905
S.Vinothkumar is on a distinguished road
Wink Re: Serialization and Deserialization

Serialization is a process through which an object's state is transformed into some serial data format, such as XML or binary format.

The reverse process of Serialization is De Serialization.

For the process of serialization we need two things. One is a Formatter and another is a Stream Object.
The class written below is the class whose object is going to be serialized. For that purpose, the <Serializable()> attribute are added.

Code:
<Serializable()> Public Class DataDescription

  Public Data As Integer
  Public Description As String
 
  Public Sub New(ByVal NewData As Integer, ByVal NewDescription As String)

    Data = NewData
    Description = NewDescription

  End Sub
 
  Public Overrides Function ToString() As String
  	Return Description
  End Function
 
End Class
Serialization function is…

Code:
Public Function SerializeData( _
  ByVal oDataToBeSerialized As Object) As System.IO.MemoryStream

  Dim oFormatter As New _
    System.Runtime.Serialization.Formatters.Binary.BinaryFormatter()

  Dim oStream As New System.IO.MemoryStream()
  oFormatter.Serialize(oStream, oDataToBeSerialized)

  Return oStream

End Function
De-Serialization

Deserialization is the process of using the serialized state information to regain the object from the serialized shape to its original shape.
So, it is basically the reverse process of the Serialization. (The name also suggests De-Serialization)

Code:
Public Function DeSerializeData(ByVal oStream As 
	System.IO.MemoryStream) As Object

  Dim oFormatter As New _
    System.Runtime.Serialization.Formatters.Binary.BinaryFormatter()

  Dim oReturnObject As Object
  oStream.Position = 0
  oReturnObject = oFormatter.Deserialize(oStream)
  Return oReturnObject

End Function
Hence the serialization and De serialization using in VB.Net.
__________________
S.VinothkumaR
Behind me is infinite power,
Before me is Endless Possibility,
Around me is Boundless Opportunity,
Why should I fear!
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
XML Serialization Using C#... shaalini C# Programming 5 03-18-2008 08:32 PM
XML Class Generator for C# using XSD for deserialization santhakumar C# Programming 2 11-20-2007 07:48 AM
Serialization and deserialization sivakumar Java Programming 1 07-17-2007 04:52 AM
Serialization leoraja8 Java Programming 1 05-10-2007 07:46 AM
XML Serialization and Deserialization Using PEAR Anandavinayagam PHP Programming 0 03-28-2007 11:51 PM


All times are GMT -7. The time now is 02:49 PM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.
Our Partners
One Way Moving Companies | Stamford Dentist | Euro Millions Lottery | Home Loans| Furniture

SEO by vBSEO 3.0.0