Replacement for XML Serialization

Matthew Scharley picture Matthew Scharley · Jul 27, 2009 · Viewed 11.9k times · Source

I have code using XmlSerializer to serialize/deserialize a data structure for persistance. I've read and heard in several places here on StackOverflow that XmlSerializer is one or more of:

  • Bad
  • Poorly supported/implemented
  • Possibly won't be supported into the future

My question is two-fold; is any of the above true, and if so, what alternatives exist? For my purposes, XML works very well, and I would like to keep that much constant, but everything else is open to change.

EDIT: If you want to suggest something other to XML, I'm open to it, but it does need to be human-readable.

Answer

Marc Gravell picture Marc Gravell · Jul 27, 2009

XmlSerializer is perfectly supportable, but has some glitches;

  • relatively slow; but usually this is still fast enough
  • only supports public members; can be a pain
  • requires write accessors lists - just ugly

However, I expect it to continue to be there for a considerable time; IMO, it is BinaryFormatter that has the real problems (when used for persistence).

I'm very biased (since I'm the author), but I'd choose protobuf-net; a binary serializer using Google's "protocol buffers" wire format; fast, portable between languages/platforms, very small output, version tolerant, etc (and free, of course). Clearly not xml, though - so not human readable.