diff --git a/Src/Newtonsoft.Json.Tests/Serialization/JsonSerializerCollectionsTests.cs b/Src/Newtonsoft.Json.Tests/Serialization/JsonSerializerCollectionsTests.cs index dd748500..45d0eed5 100644 --- a/Src/Newtonsoft.Json.Tests/Serialization/JsonSerializerCollectionsTests.cs +++ b/Src/Newtonsoft.Json.Tests/Serialization/JsonSerializerCollectionsTests.cs @@ -1817,6 +1817,41 @@ namespace Newtonsoft.Json.Tests.Serialization Assert.AreEqual("444-1212", newName.pNumbers[1].phoneNumber); } + [TestFixture] + public class MultipleDefinedPropertySerialization + { + [Test] + public void SerializePropertyDefinedInMultipleInterfaces() + { + const string propertyValue = "value"; + + var list = new List { new TestClass { Property = propertyValue } }; + + var json = JsonConvert.SerializeObject(list); + + StringAssert.AreEqual($"[{{\"Property\":\"{propertyValue}\"}}]", json); + } + + public interface IFirstInterface + { + string Property { get; set; } + } + + public interface ISecondInterface + { + string Property { get; set; } + } + + public interface ITestInterface : IFirstInterface, ISecondInterface + { + } + + public class TestClass : ITestInterface + { + public string Property { get; set; } + } + } + [Test] public void CustomCollectionSerialization() { diff --git a/Src/Newtonsoft.Json/Serialization/JsonPropertyCollection.cs b/Src/Newtonsoft.Json/Serialization/JsonPropertyCollection.cs index d9dda703..312acf66 100644 --- a/Src/Newtonsoft.Json/Serialization/JsonPropertyCollection.cs +++ b/Src/Newtonsoft.Json/Serialization/JsonPropertyCollection.cs @@ -104,6 +104,12 @@ namespace Newtonsoft.Json.Serialization // current property is hidden by the existing so don't add it return; } + + if (_type.ImplementInterface(existingProperty.DeclaringType) && _type.ImplementInterface(property.DeclaringType)) + { + // current property was already defined on another interface + return; + } } } @@ -176,4 +182,4 @@ namespace Newtonsoft.Json.Serialization return null; } } -} \ No newline at end of file +}