Json Deserialize Issue with EF and RIA Services

I have an odd problem. I use WCF RIA with Entity Framework. I've implemented a generic search functionality, which relies on sending back the resulting entities as byte[] (enter Json.Net) and I'm able to get around all sorts of limitations of strong typedness of RIA. But when I'm deserializing back in the client, my object is not properly assembled. Now what do I mean by that?

The json, technically a string, converted to byte[] by me and back on the client, contains the related entity information I need. So let's suppose the entity is called Account and it has a related Person object. The json string , even 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?

Answers


Ok, figured it out - so before deserializing I attached the below resolver to my settings like settings.ContractResolver = new DynamicContractResolver();

    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;
        }
    }

Now everything that's in the Json deserializes in to the object fully. I don't know why this isn't the default behavior.


Need Your Help

Unable to authenticate mongodb remotely

ruby-on-rails mongodb authentication heroku digital-ocean

I am unable to authenticate mongodb remotely. I'm running MongoDB 3.0.0 provided by the DigitalOcean One-Click installer, and I can't seem to set up authentication properly.

reference different workbooks worksheets using object variables The workbook is already open

excel vba variables object

I'm pounding my head against the wall with this. I've been writing the full workbooks().sheets() references. Looking for a shorter way to do it I found some stackoverflow posts and answers that see...