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

Deserializing entity doesn't deserialize child entity

Jun 13, 2012 at 4:43 PM

using EF & WCF RIA.

Let's suppose the entity is called Account and it has a related Person object. The json string , including the deserialized jobject, has this Person object and it's details. However, when I deserialize like JsonConvert.DeserializeObject<Account>(jdata, settings) - Person is null with no errors.

The settings I'm trying are here:

settings = new JsonSerializerSettings()
//CheckAdditionalContent = true,
PreserveReferencesHandling = PreserveReferencesHandling.All,
//ReferenceLoopHandling = ReferenceLoopHandling.Serialize
NullValueHandling = NullValueHandling.Ignore,
DefaultValueHandling = DefaultValueHandling.Ignore,
ObjectCreationHandling = ObjectCreationHandling.Replace,
TypeNameHandling = TypeNameHandling.Auto

Any ideas?

Jun 13, 2012 at 6:48 PM

Figured it out - by assigning a custom contract resolver and setting Ignored values to false.

	public class DynamicContractResolver : DefaultContractResolver
		protected override JsonProperty CreateProperty(System.Reflection.MemberInfo member, MemberSerialization memberSerialization)
			var r = base.CreateProperty(member, memberSerialization);
			r.Ignored = false;
			return r;

But it doesn't make much sense on a deserialization things are being ignored. After all there's a finite amount of data in the Json string.