Json.Net calls property getter during deserialization of list, resulting in duplicate items

后端 未结 1 1576
别跟我提以往
别跟我提以往 2020-12-10 15:20

I\'m using json.net to implement the memento pattern for a winform application. I\'m using the memento to rollback an object on a failed database transaction. The problem

相关标签:
1条回答
  • 2020-12-10 16:22

    Json.Net has an ObjectCreationHandling setting for this purpose. Try setting it to Replace, e.g.:

    JsonSerializerSettings settings = new JsonSerializerSettings();
    settings.ObjectCreationHandling = ObjectCreationHandling.Replace;
    
    MyObject obj = JsonConvert.DeserializeObject<MyObject>(memento, settings);
    

    Demo: https://dotnetfiddle.net/rkY1pt

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