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