This project has moved. For the latest updates, please go here.

Support for serializing System.Version

Feb 9, 2012 at 8:05 PM
Edited Feb 9, 2012 at 8:08 PM

There is currently an issue to add support for [de]serializing to/from System.Version. The person that created the issue doesn't specify what exactly is meant by "support", only saying that the current way serialization is handled is not "correct".

I'm going to assume that the desired functionality is for a System.Version object to serialize to a string in x.x[[.x].x] format, rather than a JSON object like { "Major": 1, "Minor": 0 }, etc.

However, given there are applications currently depending on that functionality, how can this be added without breaking the existing implementation?

Deserialization won't be difficult because it can fall back to regular object deserialization if the value isn't a string.

Serialization is another issue though - how will the serializer know when to use the string format vs object format? Adding some sort of specific attribution (e.g. "JsonVersionPropertyAttribute") seems a bit heavy handed just single type, but it I don't think it should just assume to use the string format.

One option could be to add a JsonConverter implementation (call it VersionConverter), but don't automatically add it into the built-in converter collections. Developers would need to decorate the property with a JsonConverterAttribute specifying the VersionConverter if they want to [de]serialize using the string format.

Feb 11, 2012 at 3:38 PM

This is completed, using the explicit VersionConverter decoration solution: