{"action":"created","issue":{"url":"https://api.github.com/repos/JamesNK/Newtonsoft.Json/issues/959","repository_url":"https://api.github.com/repos/JamesNK/Newtonsoft.Json","labels_url":"https://api.github.com/repos/JamesNK/Newtonsoft.Json/issues/959/labels{/name}","comments_url":"https://api.github.com/repos/JamesNK/Newtonsoft.Json/issues/959/comments","events_url":"https://api.github.com/repos/JamesNK/Newtonsoft.Json/issues/959/events","html_url":"https://github.com/JamesNK/Newtonsoft.Json/issues/959","id":164305018,"number":959,"title":"Newtonsoft deserialization duplicate elements when deserialize a list inside other list","user":{"login":"fgarciachipi","id":8441996,"avatar_url":"https://avatars.githubusercontent.com/u/8441996?v=3","gravatar_id":"","url":"https://api.github.com/users/fgarciachipi","html_url":"https://github.com/fgarciachipi","followers_url":"https://api.github.com/users/fgarciachipi/followers","following_url":"https://api.github.com/users/fgarciachipi/following{/other_user}","gists_url":"https://api.github.com/users/fgarciachipi/gists{/gist_id}","starred_url":"https://api.github.com/users/fgarciachipi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fgarciachipi/subscriptions","organizations_url":"https://api.github.com/users/fgarciachipi/orgs","repos_url":"https://api.github.com/users/fgarciachipi/repos","events_url":"https://api.github.com/users/fgarciachipi/events{/privacy}","received_events_url":"https://api.github.com/users/fgarciachipi/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2016-07-07T13:09:50Z","updated_at":"2016-07-07T13:11:45Z","closed_at":null,"body":"I have a list of objects (A), each object containing a list of objects (B). I did the serialization of the list of As without problems but when I did the deserialization of As the list of Bs inside of each A, has twice the original quantity of Bs.\r\n\r\n```c#\r\nvar sample = new List<A>\r\n{\r\n\tnew A\r\n\t{\r\n\t\tFlag = true,\r\n\t\tAmount = 10,\r\n\t\tBs = new List<B>\r\n\t\t{\r\n\t\t\tnew B {Amount = 4, Id = Guid.NewGuid()},\r\n\t\t\tnew B {Amount = 6, Id = Guid.NewGuid()}\r\n\t\t}\r\n\t},\r\n\tnew A\r\n\t{\r\n\t\tFlag = true,\r\n\t\tAmount = 20,\r\n\t\tBs = new List<B>\r\n\t\t{\r\n\t\t\tnew B {Amount = 4, Id = Guid.NewGuid()},\r\n\t\t\tnew B {Amount = 6, Id = Guid.NewGuid()}\r\n\t\t}\r\n\t},\r\n\tnew A\r\n\t{\r\n\t\tFlag = false,\r\n\t\tAmount = 30,\r\n\t\tBs = new List<B>\r\n\t\t{\r\n\t\t\tnew B {Amount = 4, Id = Guid.NewGuid()},\r\n\t\t\tnew B {Amount = 6, Id = Guid.NewGuid()}\r\n\t\t}\r\n\t}\r\n};\r\n\r\nvar serialized = JsonConvert.SerializeObject(sample, ContractResolver.AllMembersSettings);\r\nvar deserialized = JsonConvert.DeserializeObject<List<A>>(serialized, ContractResolver.AllMembersSettings);\r\n```\r\n\r\n```c#\r\nclass A\r\n{\r\n    public bool Flag { get; set; }\r\n    public decimal Amount { get; set; }\r\n    public List<B> Bs { get; set; }\r\n}\r\n\r\nclass B\r\n{\r\n    public Guid Id { get; set; }\r\n    public decimal Amount { get; set; }\r\n}\r\n\r\npublic class ContractResolver : DefaultContractResolver\r\n{\r\n    public static readonly JsonSerializerSettings AllMembersSettings =\r\n        new JsonSerializerSettings\r\n        {\r\n            TypeNameHandling = TypeNameHandling.All,\r\n            ContractResolver = new ContractResolver()\r\n        };\r\n\r\n    protected override IList<JsonProperty> CreateProperties(Type type, MemberSerialization memberSerialization)\r\n    {\r\n        var props =\r\n            type\r\n                .GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)\r\n                .Where(p => p.CanRead && p.CanWrite)\r\n                .Select(p => base.CreateProperty(p, memberSerialization))\r\n            .Union(\r\n            type\r\n                .GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)\r\n                .Select(f => base.CreateProperty(f, memberSerialization)))\r\n            .ToList();\r\n\r\n        props.ForEach(p => { p.Writable = true; p.Readable = true; });\r\n\r\n        return props;\r\n    }\r\n}\r\n```"},"comment":{"url":"https://api.github.com/repos/JamesNK/Newtonsoft.Json/issues/comments/231072992","html_url":"https://github.com/JamesNK/Newtonsoft.Json/issues/959#issuecomment-231072992","issue_url":"https://api.github.com/repos/JamesNK/Newtonsoft.Json/issues/959","id":231072992,"user":{"login":"fgarciachipi","id":8441996,"avatar_url":"https://avatars.githubusercontent.com/u/8441996?v=3","gravatar_id":"","url":"https://api.github.com/users/fgarciachipi","html_url":"https://github.com/fgarciachipi","followers_url":"https://api.github.com/users/fgarciachipi/followers","following_url":"https://api.github.com/users/fgarciachipi/following{/other_user}","gists_url":"https://api.github.com/users/fgarciachipi/gists{/gist_id}","starred_url":"https://api.github.com/users/fgarciachipi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fgarciachipi/subscriptions","organizations_url":"https://api.github.com/users/fgarciachipi/orgs","repos_url":"https://api.github.com/users/fgarciachipi/repos","events_url":"https://api.github.com/users/fgarciachipi/events{/privacy}","received_events_url":"https://api.github.com/users/fgarciachipi/received_events","type":"User","site_admin":false},"created_at":"2016-07-07T13:11:45Z","updated_at":"2016-07-07T13:11:45Z","body":"Newtonsoft.Json version ***9.0.1***"}}
{"actor":{"display_login":"fgarciachipi"}}