I apologize for the length of this post, but this particular problem
takes a bit of explanation.
I have a set of hierarchically-related classes that I want to serialize
on demand at runtime. There are two scenarios for serialization: the
first is what I refer to as a "reduced" values set, where I will
serialize only a selected few properties from each class in order to
reduce the wire size of the xml.
The second scenario is a "full" values set, where all public properties
of each object in the hierarchy will be serialized as part of a runtime
configuration request. This would be used for configuration transfer,
backups, etc.
I know how to prevent properties with primitive data types from being
serialized, and I know that to prevent serialization of reference
types, you just set the property value to null. The problem is, if I
set certain runtime object properties to null, I'll break a lot of
application logic.
So, here are the various ideas that I've come up with so far for
dealing with this issue:
1. Create a "reduced" schema for the first scenario, generate the
types, and instantiate them at runtime strictly for serialization
purposes.
2. Create a second copy of the full hierarchical set of objects, and
set the appropriate property values to null at the time of
serialization.
3. Create a custom Xml serializer that serializes the appropriate
properties based on which scenario is chosen.
None of these approaches seems particularly desirable. The first two
are inefficient from the standpoint of runtime memory management, and
the second approach has the added disadvantage of having to create a
mechanism for keeping the two sets of objects in sync at all times,
both at runtime and at design time. And the third approach seems
redundant, considering that the XmlSerializer class is available to do
the job.
Can anyone suggest a better alternative? 4 1365
How about you serialize the "full" set - then filter the XML output via XSL
transform to produce the "reduced" set?
<in*********@yahoo.com> wrote in message
news:11**********************@g47g2000cwa.googlegr oups.com... I apologize for the length of this post, but this particular problem takes a bit of explanation.
I have a set of hierarchically-related classes that I want to serialize on demand at runtime. There are two scenarios for serialization: the first is what I refer to as a "reduced" values set, where I will serialize only a selected few properties from each class in order to reduce the wire size of the xml.
The second scenario is a "full" values set, where all public properties of each object in the hierarchy will be serialized as part of a runtime configuration request. This would be used for configuration transfer, backups, etc.
I know how to prevent properties with primitive data types from being serialized, and I know that to prevent serialization of reference types, you just set the property value to null. The problem is, if I set certain runtime object properties to null, I'll break a lot of application logic.
So, here are the various ideas that I've come up with so far for dealing with this issue:
1. Create a "reduced" schema for the first scenario, generate the types, and instantiate them at runtime strictly for serialization purposes.
2. Create a second copy of the full hierarchical set of objects, and set the appropriate property values to null at the time of serialization.
3. Create a custom Xml serializer that serializes the appropriate properties based on which scenario is chosen.
None of these approaches seems particularly desirable. The first two are inefficient from the standpoint of runtime memory management, and the second approach has the added disadvantage of having to create a mechanism for keeping the two sets of objects in sync at all times, both at runtime and at design time. And the third approach seems redundant, considering that the XmlSerializer class is available to do the job.
Can anyone suggest a better alternative?
If you are using SoapFomatter, you can use ISerializationSurrogate. For
XmlSerializer, I don't know such equivalent option.
An excellent idea! I had not thought of that approach. I'll
investigate that further.
Thanks, Chris.
Troung,
In my application, the Xml could certainly be serialized using the
SoapFormatter. I'll check that out as well.
Thanks! This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Arran Pearce |
last post by:
Hi,
I have just looked at serialization (to a file) and was surprised how easy
it seemed to be. Are there any issues when serializing objects? or is it
really just that easy and powerful and I...
|
by: Adam H. Peterson |
last post by:
I have an application that uses C++ file streams for storing the state
of complex objects to be later read in, ideally reconstructing the state
of the object as when it was serialized. One issue...
|
by: Jeff T. |
last post by:
Hello,
I have an existing set of C# classes that encapsulate our application data.
They are in a heirachy with each subclass defining more specific types of
data. I would like to serialize these...
|
by: Mountain Bikn' Guy |
last post by:
We have an app that computes a lot of numeric data. We would like to save to
disk about 1-2 gigabytes of computed data that includes ints, doubles,
strings and some complex objects that contain...
|
by: Dominic |
last post by:
Hi everybody,
I'm planning to use serialization to persist an object (and possibly
its child objects) in my application. However, I'm concerned about the
backward compatibility issue. I'm...
|
by: Dave Veeneman |
last post by:
I'm working on a project where I have to persist data to a file, rather than
to a database. Basically, I need to save the state of several classes, each
of which will have a couple of dozen...
|
by: oDDskOOL |
last post by:
I realized today that the Hashtable.Clone only produces a shallow
copy... that makes me go mad that M$ doesn't even provide a deep copy
ctor for the Hashtable class !
mighty tech ducks might...
|
by: nickdu |
last post by:
We have the need to persist data to a configuration database. We want the
format of this data to be XML. There are two approaches that come to mind
that seem to fit the bill. Below are the two...
|
by: CJ Taylor |
last post by:
hey everyone, thought I would ask this here because the web service groups
seems pretty light on conversation. I'm buliding a web service, but keep
getting this error. I understand the error,...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |