1

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?

4

1 に答える 1

2

わかりました-それで、デシリアライズする前に、以下のリゾルバーを次のように設定にアタッチしました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;
        }
    }

これで、Json 内のすべてがオブジェクトに完全に逆シリアル化されます。これがデフォルトの動作ではない理由がわかりません。

于 2012-06-13T18:40:20.033 に答える