A few weeks back I wrote a class to help serialize/deserialize objects file. The file format requested was json, then compressed. After some coding/testing I settled on this design:
2 design decisions I'm not proud of:
- During research, we found that if we passed a very large
Listof objects, the serialize/deserialize would leak memory. So I settled on a generic class, that you have to pass in a
List<T>of the generic to
SaveObjectsand get back an
SaveObjects. As long as your type isn't a very large list, you don't leak memory. BTW, the leak happened when I used json.net also.
LoadObjectsthe deserialization stops via an exception check. Because of the nature of deserialize (typically done once for the object tree) and the fact I'm loading lists (see point 1), I have no other way of stopping the deserialization.
It seems to work fine, but I'm not the proud of this design.