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....
| |||||||
| Register | FAQ | Members List | Calendar | Mark Forums Read |
|
#1
| |||
| |||
| Hui Guys can anyone tell me What do you mean by Serialization and Deserialization and it's use. |
|
#2
| |||
| |||
| 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>
|
|
#3
| |||
| |||
| 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 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 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
__________________ S.VinothkumaR Behind me is infinite power, Before me is Endless Possibility, Around me is Boundless Opportunity, Why should I fear! |
![]() |
| Thread Tools | |
| Display Modes | |
| |
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 |
Our Partners |