serialization

Deserializing an xml stream with invalid values

I'm calling a "web service" that gives me as an xml response an invalid node, so when I try to deserialize it, it throws an exception. I'm using the XmlSerializer class, like so: internal class Response<T> { public Response(byte[] xml) { XmlSerializer s = new XmlSerializer(typeof(T)); XmlReader reader = XmlReade...

Maintaining xml hierarchy (ie parent-child) information in objects generated by XmlSerializer

Hello all, for some time now I have been trying to solve the following problem and I'm starting to run out of ideas: I have generated a set of C# classes from an xsd schema using the xsd.exe tool and deserializing xml files works fine. The problem is that apart from the convenience and safety of using the auto generated classes, I also...

Quick and dirty reflection based XML Serializer

Does anyone know of a quick and dirty implementation of a reflection based XML serializer? I am looking to rip out my XML serialization code due to the horrid start up time. I know about sgen.exe but do not want to complicate my build and packaging process. We use the XML serialization at startup to pull out configuration values from...

Serializing objects into the database while maintaining flexibility

What approach should I take when serializing an object to the database, keeping in mind that the objects properties will change in time? At first, I thought of making sure all my objects implement an interface, but what happens when an interface looses a property and gains another. What happeneds to the existing serialized data in the d...

How to serialize a derived class as its base class

I have a derived class that adds only methods to a base class. How can serialize the derived class so that it matches the serialization of the base class? i.e. The serialized xml of the derived class should look like: <BaseClass> ... </BaseClass> e.g. The following will throw an InvalidOperationException "The type DerivedClass was n...

WCF, containers in DataContract

Hi I need to pass some container of objects to WCF call [DataContract] class Foo { // other fields omited [DataMember] public List<Foo> MyList; } Is it OK for serialization? If not what are my options? ...

Dictionary not deserializing

I'm having a problem where one Dictionary in my project is either not serializing or not deserializing. After deserializing, the data I serialized is simply not in the object. Here's the relevant snip of the class being serialized: class Person : ISerializable { private Dictionary<Relation,List<int>> Relationships = new Dictionary<...

Update model object with new dynamicaly created field?

I have Queryset: queryset = Status.objects.all()[:10] Model Status hasn't got field commentAmount so I would add it to every object in Queryset: for s in queryset: s.commentAmount = s.getCommentAmount() All is fine, print s.commentAmount shows good results, but after: response = HttpResponse() response['Content-Type'] = "text/j...

If Base class is marked Serializable are all child classes marked too?

I have a whole list of entity classes which I need to make Serializable (due to storing session state in SQL, but that's another story). I have added the attribute [Serializable] and all seems to be fine. All of my entity classes extend from the same base class. If I mark the base class as Serializable, does this mean all children ar...

error marshalling return;

I am getting the following exception when I tried to execute one my service in my server which is deployed as EJB2.0 stateless session bean. Error executing services::error marshalling return; nested exception is: java.io.NotSerializableException: xxx.xxx.xxx.PmsService here xxx.xxx.xxx.PmsService is my class which is already implem...

Problem with serialization derivative class in C#

I have a code like this: [Serializable] public class A { public int X { get; set; } } [Serializable] public class B : A{ } [Serializable] public class C { public A A { get; set; } } ... public string Serialize<T>(T obj) { StringBuilder stringBuilder = new StringBuilder(); TextWriter stringWriter =...

Is there any way to do custom serialization in WCF?

In my WCF solution, the server doesn't need to know the data type. The client will send a type and receive the same type. For performance reasons I think I could implement serialization manually in the client proxy, avoiding WCF builtin serialization on the server side, but there is any way to achieve the same goal just configuring WCF ...

Is the binary formatter smart about space when serializing?

Short and simple: If I have an object with many values == to their default constructor values, will a serialization with a binary formatter omit them in the resulting file to save space? I'm figuring, since the value is known from the class definition anyway. ...

Generic JSON parser in .NET / WPF?

Hi guys, I've read lots of tutorials on how to deserialize a JSON object to an object of a particular using DataContractJsonSerializer. However, I'd like to deserialize my object to a Dictionary consisting of either Strings, Arrays or Dictionaries, such as System.Json does with SilverLight when I say JsonObject.Parse(myJSONstring). Is ...

.net xml serialization

I used the xsd utility to generate a *.cs file from an *.xsd file. I'd like to generate xml from this generated class by serializing an instance of the class. Is there any way to get 'clean' output like this: <header> <br/> <br/> <br/> <br/> </header> Here are two examples of the not clean output I am getting: <header> <...

Switching on class type in C#

I have a bunch of stored, serialized classes (that all inherit from a base class) in C#. Along with the serialized class, I also store an enum value that identifies the which subclass is serialized. This means that whenever I want to serialize/deserialize the class, I've got to use a couple of big switch statements based on the enum to...

.NET WebService Sending Large XML File

I have a list of objects List that I need to send over a web service. The list contains about 37,000 Objects. This translates to about a 125 MB XML File if I serialized it to XML. I think by default web services communicate via serialized XML. This leads me to believe I am actually sending 125MB file each time. In binary format this...

Creating a class for JSON deserialization

Consider the following JSON: { "Code": 2, "Body": { "Dynamic-Key": { "Key1": "Val1", "Key2": "Val2" } } } Defining the following classes structure: [DataContract] class JsonResponse { [DataMember] public string Code { get; set; } [DataMember] public JsonResponseBo...

Can objects created with .net reflection be serialized?

Is it possible to serialize an object that is created through reflection? I get an error of "Unable to cast object of type 'testNameSpace.ScreenClass' to type 'testNameSpace.ScreenClass'" when attemping to perform the serialization of the object that was created through reflection. The error does not make sense since the types are ident...

.NET XmlSerializer Compiling Type Schemas Reader/Writer

For my application, I need to serialize data to file using XML, so I read Introducing XML Serialization on MSDN. One thing that concerns me is under the Security Considerations for XmlSerializer Applications section it reads: The XmlSerializer creates C# (.cs) files and compiles them into .dll files in the directory named by th...