This project has moved and is read-only. For the latest updates, please go here.

JSON.NET and forward-compatible data contracts / round tripping

Sep 18, 2012 at 5:18 PM

I'm currently working on an enterprise-scale business entity structure that uses JSON.NET via Web API to serialize and deserialize entities.

WCF's data contracts and XML serializer supports the concept of "forward compatibilty" using the IExtensibleDataObject interface.

Consider the following scenario:
1) Client and server are developed using Version 1.0 of Business Entities assembly
2) In version 2.0, a new property is added to one of the Business Entities. The server is upgraded to support the new version.
3) A client somewhere remains on the old version of the assembly (ie/ imagine large company where not everything can be upgraded at once!)
4) Client loads data from server. During deserialization the "new" property is thrown away or ignored. (However, in JSON.NET there appears to be a bug where the *entire* entity becomes null!)
5) Client changes one field, submits entire entity back to server.
6) Server deserializes entity - property added in version 2.0 is missing
7) Server updates database, setting field to null. DATA LOSS!

WCF solves this problem using the IExtensibleDataObject interface. When a "new" (unrecognized) property is discovered, it tosses the data into an ExtensionDataObject that's stored in the entity. When the entity is re-serialized, the serializer reads the ExtensionDataObject to load the those properties again.

I'd love to see JSON.NET add support for round-tripping via the interface, perhaps making a new enum value in MissingMemberHandling and having it be the default. It's a key enterprise scenario that I don't have a workaround right now for.