This is my class structure:
class DataItem
{
public string Id { get; set; }
public string Type { get; set; }
private Dictionary
The short answer: You cant
This is because even though you can imagine the serialization scheme, .NET Serializer cannot guarantee that the keys re-serialized will have the same hash value.
Long answer: You can, but it's a lot of work
The solution for you is to either do manual serialization of the entire object, or to replace Dictionary with a simple Wrapper Property that wraps IDictionary
, but exposes it as a list of pairs. (you can convert it later if you need it.)
However: this leaves the same problem as above, you cannot gaurantee a re-serialized key will have the same hashcode as before it was serialized.