473,320 Members | 1,832 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Serialization of a complicated class

Hi,

I need to write a serialization (to XML string) and restoring (from XML
string) of a very complicated object. The object uses a few classes, one
class has two ArrayLists, etc. The general structure supposes to have 2-3
levels.

What's easier, to write a serialization method for each class used by the
main class and a short method to gather all these XML strings together into
one complex string or to use some trick and serialize the whole structure
into one XML?

I expect that this structure will be changing and the deserialization should
read all previous versions, so that Ser./Deser. methods should be created
now to support all further versions.

Did anybody write these methods for a very complicated class? What's
experience?

Thanks,
Dmitri

Nov 16 '05 #1
2 2485
You could try using SOAP to serialize the class to see if it meets your
needs.

To serialize to soap you first need to add a reference to the SOAP formatter
(System.Runtime.Serialization.Formatters.Soap).

The use some code like this:

SoapFormatter form = new SoapFormatter();
form.Serialize(st, myInstance);

Where st is a stream (a file stream, or memory stream or something), and
myInstance is the instance of your object.

Then to deserialize the object, use something like:

myInstace = (MyClass) form.Deserialize(st);

SOAP generally works quite well with version changes.

Hope that helps.
John

"Just D" <no@spam.please> wrote in message
news:By6Bc.2066$DQ4.706@fed1read05...
Hi,

I need to write a serialization (to XML string) and restoring (from XML
string) of a very complicated object. The object uses a few classes, one
class has two ArrayLists, etc. The general structure supposes to have 2-3
levels.

What's easier, to write a serialization method for each class used by the
main class and a short method to gather all these XML strings together into one complex string or to use some trick and serialize the whole structure
into one XML?

I expect that this structure will be changing and the deserialization should read all previous versions, so that Ser./Deser. methods should be created
now to support all further versions.

Did anybody write these methods for a very complicated class? What's
experience?

Thanks,
Dmitri

Nov 16 '05 #2
You can instruct the XML Serializer how to translate your properties into XML using attributes:

[Serializable]
public class Order
{

public Order() //parameterless constructor is needed for deserialization
{
}

[XmlAttribute("Date")]
public string Date
{ get{ .... } set{....}}

private ArrayList mLines = new ArrayList();
[XmlArray("Lines")]
[XmlArrayElement("Line",typeof(OrderLine))]
public IList OrderLines
{
get
{
return mLines;
}
}


}

If you add new properties to your class, the deserializer will still be able to read old files.
These properties will retain their default value.
If you remove properties, the deserializer will ignore the XML nodes he doesn't recognize.
Just make sure you don't change the return types of properties, because then you will get exceptions.

Regards,
Marc Selis
"Just D" <no@spam.please> wrote in message news:By6Bc.2066$DQ4.706@fed1read05...
Hi,

I need to write a serialization (to XML string) and restoring (from XML
string) of a very complicated object. The object uses a few classes, one
class has two ArrayLists, etc. The general structure supposes to have 2-3
levels.

What's easier, to write a serialization method for each class used by the
main class and a short method to gather all these XML strings together into
one complex string or to use some trick and serialize the whole structure
into one XML?

I expect that this structure will be changing and the deserialization should
read all previous versions, so that Ser./Deser. methods should be created
now to support all further versions.

Did anybody write these methods for a very complicated class? What's
experience?

Thanks,
Dmitri

Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

37
by: Ben | last post by:
Hi, there. Recently I was working on a problem where we want to save generic closures in a data structure (a vector). The closure should work for any data type and any method with pre-defined...
3
by: Aaron Clamage | last post by:
Hi, I'm not sure that if this is the right forum, but any help would be greatly appreciated. I am porting some java serialization code to c# and I can't figure out the correct way to do it. ...
6
by: Uttam | last post by:
Hello, We are at a very crucial decision making stage to select between .Net and Java. Our requirement is to download a class at runtime on the client computer and execute it using remoting or...
3
by: Alexander | last post by:
When i store rule on PC with .NET.SP1 i cant restore them from PC without SP1. An i get this Error: System.Runtime.Serialization.SerializationException: Possible Version mismatch. Type...
27
by: Codemonkey | last post by:
Heya All, Sorry, but I think it's about time for a monkey-ramble. I've just had enough of trying to serialize even simple objects with VB. A simple task you may think - stick the...
10
by: SStory | last post by:
My app is near completed for the basic feature of version 1.0. I have an extensive object model and I now want to persist my objects using serialization. I have chosen binaryformatter to...
11
by: William | last post by:
I'm looking for an example that would show how to serialize a c++ object at it's simplest w/o using any other api's. I have a class that I want to serialize and then pass to my obj-c class so I can...
0
by: bharathreddy | last post by:
Before going to that i want to say few thing on serialization : Serialization is the process of converting an object into a form that can be readily transported. For example, you can serialize an...
2
by: mkvenkit.vc | last post by:
Hello, I hope this is the right place to post a question on Boost. If not, please let me know where I can post this message and I will do so. I am having a strange problem with std::string as...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.