Deserializing $ref and $id

后端 未结 3 478
梦如初夏
梦如初夏 2021-01-07 05:03

So I\'m trying to deserialize an object that has properties: $ref and $id. I have tried going between Dictionary as well as an object where I have specified namingconvention

相关标签:
3条回答
  • 2021-01-07 05:27

    This answer worked for me: Json.Net adding $id to EF objects despite setting PreserveReferencesHandling to "None"

    In your implementation of DefaultContractResolver/IContractResolver, add this;

    public override JsonContract ResolveContract(Type type) {
        var contract = base.ResolveContract(type);
        contract.IsReference = false;
        return contract;
    }
    
    0 讨论(0)
  • 2021-01-07 05:36

    I have the same issue when trying to deserialize a swagger/json schema document. The solution is:

    JsonSerializerSettings settings = new JsonSerializerSettings();
    settings.MetadataPropertyHandling = MetadataPropertyHandling.Ignore;
    
    0 讨论(0)
  • 2021-01-07 05:41

    You'll find that $ref & $id are special properties used by Json.NET to manage multiple instances of objects in a single object graph.

    By putting these keys into your dictionary the deserialize process is trying to parse these as references to objects that don't exist.

    Try altering the keys.

    0 讨论(0)
提交回复
热议问题