473,473 Members | 1,534 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Changing Serialized Objects

Hi,

What's the easiest way of modifying an object which has been serialized to a
DB? The previous developer created a complex object hierarchy and binary
serialized the whole thing to a single field in SQL server. I need to
modify the object hierarchy, but every time I do so, I can no longer
deserialize the incoming data because my updated object has more members
than the original object.

The object is about 15 levels deep and contains several custom collections,
arraylists and other stuff, so I'm looking to automate this if possible.
I've looked briefly at reflection (which I believe may hold the answer) but
if there's already some popular method of achieving this out there.. Surely
someone else must have had the same problem?

Thanks,

Russ
Nov 22 '05 #1
2 1440
You can customize the construtor that was built for deserialization to
handle the cases where your new fields don't exist. For example, if you add
an Integer called X to the object, you can wrap the code in the constructor
to retrieve the value for X in a Try...Catch and put some default value in
if you cannot retrieve the value:

Public Sub New(ByVal info As SerializationInfo, ByVal context As
StreamingContext)
....
Try
Me.X= CType(info.GetValue("X", GetType(Integer)), Integer)
Catch ex As SerializationException
' X is not in the object being deserialized - assign a default value
Me.X = 0
End Try
....
End Sub

Brian Davis
http://www.knowdotnet.com
"Russ" <ru**@UKS.com> wrote in message
news:uQ**************@TK2MSFTNGP12.phx.gbl...
Hi,

What's the easiest way of modifying an object which has been serialized to a DB? The previous developer created a complex object hierarchy and binary
serialized the whole thing to a single field in SQL server. I need to
modify the object hierarchy, but every time I do so, I can no longer
deserialize the incoming data because my updated object has more members
than the original object.

The object is about 15 levels deep and contains several custom collections, arraylists and other stuff, so I'm looking to automate this if possible.
I've looked briefly at reflection (which I believe may hold the answer) but if there's already some popular method of achieving this out there.. Surely someone else must have had the same problem?

Thanks,

Russ

Nov 22 '05 #2
Thanks very much Brian.

With your help I think I can solve my problem.

Russ

"Brian Davis" <br***@knowdotnet.nospam.com> wrote in message
news:%2***************@TK2MSFTNGP11.phx.gbl...
You can customize the construtor that was built for deserialization to
handle the cases where your new fields don't exist. For example, if you add an Integer called X to the object, you can wrap the code in the constructor to retrieve the value for X in a Try...Catch and put some default value in
if you cannot retrieve the value:

Public Sub New(ByVal info As SerializationInfo, ByVal context As
StreamingContext)
...
Try
Me.X= CType(info.GetValue("X", GetType(Integer)), Integer)
Catch ex As SerializationException
' X is not in the object being deserialized - assign a default value
Me.X = 0
End Try
...
End Sub

Brian Davis
http://www.knowdotnet.com
"Russ" <ru**@UKS.com> wrote in message
news:uQ**************@TK2MSFTNGP12.phx.gbl...
Hi,

What's the easiest way of modifying an object which has been serialized to
a
DB? The previous developer created a complex object hierarchy and

binary serialized the whole thing to a single field in SQL server. I need to
modify the object hierarchy, but every time I do so, I can no longer
deserialize the incoming data because my updated object has more members
than the original object.

The object is about 15 levels deep and contains several custom

collections,
arraylists and other stuff, so I'm looking to automate this if possible.
I've looked briefly at reflection (which I believe may hold the answer)

but
if there's already some popular method of achieving this out there..

Surely
someone else must have had the same problem?

Thanks,

Russ


Nov 22 '05 #3

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

Similar topics

1
by: Nels P. Olsen | last post by:
If you serialize an object graph to persist it somewhere (e.g. a database) between application sessions, then you run into trouble if the serialized objects' existing field order or datatypes change,...
2
by: Russ | last post by:
Hi, What's the easiest way of modifying an object which has been serialized to a DB? The previous developer created a complex object hierarchy and binary serialized the whole thing to a single...
2
by: Christopher Ambler | last post by:
I have a class that I deserialize into as such: public class row { public string RecordFound; public string IsExpired; }
0
by: Ray Mitchell | last post by:
Hello, The result of auto-converting some Java code to C# yielded the following upgrade issue regarding the original Java call to "reset()": public virtual void writeObj(Object obj) {...
1
by: Bill Cohagan | last post by:
We are attempting to convert an already existing application over to using multiple worker processes; thus we need to store state via session state server rather than in process. Since this app...
7
by: Neal Andrews | last post by:
Hi All, Does anyone know how to stop Events from being serialized in a class that uses the <Serializable()> attribute? I have tried using the <NonSerialized()> attribute but for some bizarre...
9
by: Raphael Jolivet | last post by:
Hello there, I have a bunch of objects that I store in a text file (to store preferences), after having serialized them with JSON. Let's say I have my object : obj1 = { a : 1
0
by: rlaemmler | last post by:
Hi, I just migrated my web app to .NET 2.0. Part of the app creates some business objects from a MySQL query which is returned by a web service. Some of those objects contain DateTime...
3
by: MMiGG | last post by:
Hi Our project need parse JAVA serialized object string in C, has any library? Thanx
6
by: Matthew | last post by:
Hi, I want to change the precision level of floating point variables and calculations which is done in php.ini. However the server I rent for my domain does not give me access to php.ini,...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
Oralloy
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,...
0
jinu1996
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...
0
tracyyun
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...
0
agi2029
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,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.