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


WebAPI serialization fails with Entities


I'm using .NET's WebAPI for creating web services. Using it with MongoRepository I ran into an issue where the serialization from the JSON to my models inheriting from Entity doesn't work, none of the properties are captured. I found out that it is because of the DataContract and DataMember attributes used inside the Entity class within MongoRepository. Once I removed those the JSON serialization worked for my models.
Closed Feb 12, 2015 at 6:02 PM by RobIII
Today we moved the MongoRepository project to GitHub so I would kindly like to request you open your issue there if you still want to comment / discuss or think the issue is not ready to be closed yet to keep everything in one place.

We're sorry for any inconvenience.


fbrooke wrote Aug 30, 2014 at 11:51 PM

Adding this attribute after the DataContract one rather than removing it also solved the issue

RobIII wrote Sep 5, 2014 at 8:39 PM

Won't that break serialization for others wich would want to "OptIn"? I don't see how I could keep both 'camps' happy? I'm currently in a hurry and can't see the direct consequences this change would have. I'd have to investigate a bit more. I'll try to get back to this soon.

wrote Dec 2, 2014 at 4:49 PM

fbrooke wrote Dec 26, 2014 at 11:15 AM

The problem was that the DataContract attribute forced opt in serialization and I didn't realise at the time. I didn't want to clutter my models with DataMember attributes on each property when all my properties were intended to be serialized.
Maybe you should rethink having the DataContract attribute. MSDN says the attribute does not inherit but the Json.NET library doesn't adhere to that
Similar experience is described here

wrote Feb 12, 2015 at 6:02 PM