serialization

Serializing to XML via DataContract: custom output?

I have a custom Fraction class, which I'm using throughout my whole project. It's simple, it consists of a single constructor, accepts two ints and stores them. I'd like to use the DataContractSerializer to serialize my objects used in my project, some of which include Fractions as fields. Ideally, I'd like to be able to serialize such o...

Saving a Dictionary<String, Int32> in C# - Serialization?

Good morning, I am writing a C# application that needs to read about 130,000 (String, Int32) pairs at startup to a Dictionary. The pairs are stored in a .txt file, and are thus easily modifiable by anyone, which is something dangerous in the context. I would like to ask if there is a way to save this dictionary so that the information c...

Can OnDeserializedAttribute be used instead of IDeserializationCallback interface?

As MSDN states here, it can. But I've spent 2 hours digging mscorlib code, because in some cases the BinaryFormatter called my method marked with OnDeserialized BEFORE deserialization constructor. That is, the order was OnDeserializing(StreamingContext context) OnDeserialized(StreamingContext context) .ctor(SerializationInfo info, Stre...

Which KiokuDB backend is suitable for my serialization needs?

I use KiokuDB to store a couple of Moose objects and a couple of simple array structures (hashes and arrays). I do not need any fancy searches, transactions etc., simple the ability to fetch (lookup) an object. Also, as soon as I'm done creating the DB, it can be set read-only. No changes will ever be made to it. The main (only?) reaso...

Why can DateTime.MinValue not be serialized in timezones ahead of UTC?

I am experiencing issues with a WCF REST service. The wire object that I try to return has certain properties not set, resulting in DateTime.MinValue for properties of type DateTime. The service returns an empty document (with HTTP status 200 ???). When I try to call JSON serialization myself, the exception that is thrown is: Seriali...

C# Serialize object with string property values as CDATA

Hi all, I have the following XSD which is generated to a class. <xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" id="sales" xmlns:xs="http://www.w3.org/2001/XMLSchema"&gt; <xs:element name="sales"> <xs:complexType> <xs:sequence minOccurs="0" maxOccurs="unbounded"> <xs:element name="sale">...

Performing a DeepCopy(clone) when Events are Attached

When you have an object that provides events and you use a deepclone (serialisation) approach to cloning the object, how do you do it when there are events on the object that are actually attached. If my object declares an event, but nothing is attached then object can be cloned without issue. BUT if the object has had events attached,...

Java Serialization Issue

When I serialize the abstract class does the inheriting subclasses will also be serialize? Does this include the members of abstract class and its subclasses? public abstract class RootClass implements Serializable{ Object data; } public class SubClassA extends RootClass{ Object dataA; } public class SubClassB extends RootClass{ Ob...

Is there a reason I should NOT serialize my (Moose) objects using Storable or YAML?

I have a few Moose objects and some other simple hash objects (hashes, arrays) I'd like to serialize. At first, I used a simple my $obj_store_file = nstore($obj); and my $obj = retrieve($obj_store_file); This worked well. Later, I found about MooseX::Storage and KiokuDB. I tried using them to enjoy some benefits they have, but: ...

XML Serialization for collection types

Does anyone have an implementation for object serialization that support collections, such as ICollection, IEnumerable, IList, IDictionary? Below is my implementation, and it’s not so clean. [Serializable] public abstract class IXmlable { public virtual string ToXml() { Type type = GetType(); PropertyInfo[] pro...

why DataContractSerializer is faster that xmlSerializer ?

Performance wise, why and how Datacontract serializer is better than xmlserializer ? ...

Why do I have to load a Perl class to use its object I deserialize from YAML?

I was trying to serialize some (Moose) objects with YAML -- simply by using YAML's Dump() and Load(). After loading a serialized object, it didn't 'work' until I added a use statement with the original module name. If I don't use use I won't get any error until I try to invoke some object method, then it will croak saying it can't find ...

F# Serialization of Record types

I know how to serialize in F# using mutable objects, but is there a way to serialize/deserialize using record types using either XmlSerializer or the DataContractSerializer? looks like there is a way to do this for a discriminated union using the KnownType attribute, but i am looking for a way to use non-mutable records without default c...

C#: Deserializing JSON primitives into .NET complex types

I have a file named config.json. Here's its contents: { dataSources: [ "http://www.blahblah.com/blah", "http://www.blahblah.com/blah2", ... ], skills: [ { "name": "foobaris", "regex": "pattern" }, ... ] } I want to create a Config object o...

C# Serialize EventArgs to Xml

I am trying to serialize an object that contains an EventArgs object. If I ignore the EventArgs object upon serialization, everything works fine, but if I don't put an [XmlIgnore] above it, the application crashes with the error message System.InvalidOperationException was unhandled Message=There was an error generating the XML docume...

Is there any way to override what string value my custom type gets converted to when serializing via DataContract?

In my music/rhythm game, I using serialization in order to save user-created simfiles (think music tabs or notecharts). Nothing too earth-shattering there. But, I'm using a DataContract in order to perform the serialization, because: 1) I need private and protected fields serialized as well. I don't care if they're visible, mainly due t...

What are some good alternative serialization formats?

I have used XML in the past, but it is very verbose and clunky. We are currently using YAML, but I am finding that most developers have alot of trouble with the whitespace. Is there a YAML like format that is whitespace insensitive, but not as verbose as XML? ...

Custom WinForms Control -> Serialization

I've written a small framework. Then I've written a new WinForms control, which hosts my one framework, and a designer. Now my problem: The host control has a property of a class type. Whatever I try: The property is lost at runtime. Could someone explain me, what attributes I need? ...

HtmlAgilityPack: Convert parsed Javascript string to JSON

Hello! So, I am using the HtmlAgility pack (http://htmlagilitypack.codeplex.com/) to parse a script node and then I use regular expressions to parse out an object definition. The string I end up with is plain javascript that defines an object. Here is the sample Javascript I am trying to parse: <!--Module 328 Buying Options Table--> <...

How to write dynamically allocated structure to file.

Hi, I have a complex structure in a C program which has many members that are dynamically allocated memory. How do I write this structure to a text / binary file? How will I be able to recreate the entire structure from the data read from the file. struct parseinfo{ int varcount; int termcount; char **variables; char **terminals; ...