Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

serialize and deserialize, is it really necessary?

Posted on 2010-11-23
8
Medium Priority
?
574 Views
Last Modified: 2012-05-10
I have a method in which sets the value of an object with some properties objBandeja
1. Serialize this object: strobjBandeja = CFunciones.SerializeObject (Of EBandeja) (objBandeja), whose code is
public static string SerializeObject<T>(T obj)
        {
            try
            {
                string xmlString = null;
                System.IO.MemoryStream memoryStream = new System.IO.MemoryStream();
                System.Xml.Serialization.XmlSerializer xs = new System.Xml.Serialization.XmlSerializer(typeof(T));
                System.Xml.XmlTextWriter xmlTextWriter = new System.Xml.XmlTextWriter(memoryStream, System.Text.Encoding.UTF8);
                xs.Serialize(xmlTextWriter, obj);
                memoryStream = (System.IO.MemoryStream)xmlTextWriter.BaseStream;
                xmlString = UTF8ByteArrayToString(memoryStream.ToArray());
                return xmlString;
            }
            catch
            {
                return string.Empty;
            }
2. The following line of code is this
objEGeneral = WFGDHUtilitario.DeserializeObject(Of EGeneral)(oLSolicitud.fentListarBandejaWFGDH(strobjBandeja))

in which sending the serialized object. FentListarBandejaWFGDH method code is on file: 2 fentListarBandejaWFGDH.txt
3. analyzing the code does the following
3.1 deserialize the xml variable objEBandeja = CFunciones.DeserializeObject (Of EBandeja) (pstrOBJEBandeja)
3.2 gets the value of a property and that value calculates the value of some variables that will be sent to a stored procedure

MY QUESTION IS, in this case in order to serialize and deserialize is to calculate the parameter of the stored procedure?
0
Comment
Question by:enrique_aeo
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 5

Expert Comment

by:buraksarica
ID: 34203187
I could not understand exactly what your question is.
0
 

Author Comment

by:enrique_aeo
ID: 34204324
do not understand why serialize and deserialize. I understand the concept but I do not understand its use
0
 
LVL 16

Accepted Solution

by:
kris_per earned 1336 total points
ID: 34204911

I think Serialize/Deserialize is used to create another copy of the object objBandeja. If some operations change the internal state of an object and if you dont want keep this change in the object, then the way is to create a copy of the object and do the operation on the copy; so internal changes will be only in the copy and first object will remain the same.

In your question:
step 1: serialize orginal object to get it as xml string
step 3.1: deserialize the xml string to get an object which will be a copy of the original object
step 3.2: operation in this step I think changes some value in the second object.

Thus by doing step 3.2 on the second object, the original object remain unchanged I think which is the purpose.

See if this fits.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 21

Expert Comment

by:Alpesh Patel
ID: 34205113
It is useful when you are passing object over network to improve performance. Because serialization reduce the use of bandwidth.
0
 
LVL 29

Assisted Solution

by:Nightman
Nightman earned 664 total points
ID: 34207745
In this case, the purpose of deserialization is most likely the transfer of the data object between two dissimilar applications or systems, or incompatible languages. Since the object can be represented in xml, the provider or client simply provides it in a textual representation of the class.

The consuming application simply deserializes the stream back into an object that it can consume (which should implicitly validate the properties based on type) and has probably implemented some validation as well (and as you say, calculations in the code based on other properties) before it calls a stored procedure on the database. This allows them to re-use the same class in multiple locations in their code without having to write a parser and without the overhead of the XML DOM.

"I think Serialize/Deserialize is used to create another copy of the object "
That would appear to be a particularly expensive way of creating a copy. Simpler to implement an ICloneable interface and copy the properties in memory.

"It is useful when you are passing object over network to improve performance"
Not with XML serialization - it's effectively string parsing, which is notoriuosly slow. For a performant solution, binary would be significantly better.
0
 

Author Comment

by:enrique_aeo
ID: 34234462
Thanks experts, i travel and recently can respond. Their responses are very interesting, i am atachando the method that lack, with that we are going to have a better idea, i hope their support.
0
 

Author Comment

by:enrique_aeo
ID: 34234468
the file with method fentListarBandejaWFGDH
2-fentListarBandejaWFGDH.txt
0
 
LVL 16

Assisted Solution

by:kris_per
kris_per earned 1336 total points
ID: 34238831
This function does the following:

   Deserialize the xml string parameter to get objEBandeja(EBandeja type) object.

   Use the Filtro member of objEBandeja object to use in sql parameters in the stored proc.

   Results of stored proc is stored in objEGeneral(EGeneral type) object.

   Serialize the objEGeneral object to get xml string and return xml string.


I think the reason why it uses Deserialize/Serialize depends on the requirement of the caller and what input the caller has.

If the caller already has objEBandeja(EBandeja type) object, then this function can be changed to take objEBandeja(EBandeja type) object as parameter; then there is no need to do the first Deserialize.

If the caller needs the return result as objEGeneral(EGeneral type) object, then the function can just return objEGeneral(EGeneral type) object instead of xml string; then there is no need for the final serialize.

It looks this function is a helper fuction for the caller to suit its need. I dont see any other special use here (like to create a copy or to transfer the object across network or systems)

Hope this helps.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question