Serialization issue

Serialization issue

Old forum URL: forums.lhotka.net/forums/t/4088.aspx


shaih posted on Wednesday, December 26, 2007

Hi,

 

I have constructed several business objects similar to the design of the ProjectTraker example. I am now trying to get an XML representation of the created objects and I am running through some issues.

Since XMLSerializer only serializes public fields or properties - what can I do with the read only type objects (although they all have public properties that implement get functionality the XMLSerializer will only serialize properties implementing both get and set)?

I also added an empty constructor to NameValueListBase in order for the inherited  NameValueListBase objects.

 

Any insights?

Thanks

Shai

tmg4340 replied on Wednesday, December 26, 2007

What do you need the XML representation for?  If we knew that, we could potentially make better suggestions.

FWIW, you could look at implementing the IXmlSerializable interface - it's designed to customize how .NET's XML serializers work with your objects.  But that's a bit of work, and depending on what you need the XML for, I wouldn't necessarily recommend that approach.

CSLA objects don't necessarily play well with .NET's XML serializers, which is one of many reasons why Rocky suggests an alternate approach when discussing web services.

- Scott

ajj3085 replied on Wednesday, December 26, 2007

I wouldn't add public default constructors.  That creates all kinds of problems.

I think what you need to do is implement IXmlSerializable, so that you can take full control over the serialization process.  You'll have to write a bit of code to do this, but you won't be breaking your business object design to do so.

Copyright (c) Marimer LLC