-Fixed non-public base class properties being used instead of child class properties
This commit is contained in:
@@ -75,4 +75,4 @@ using System.Security;
|
|||||||
// by using the '*' as shown below:
|
// by using the '*' as shown below:
|
||||||
|
|
||||||
[assembly: AssemblyVersion("6.0.0.0")]
|
[assembly: AssemblyVersion("6.0.0.0")]
|
||||||
[assembly: AssemblyFileVersion("6.0.1.17109")]
|
[assembly: AssemblyFileVersion("6.0.1.17115")]
|
||||||
|
|||||||
@@ -268,6 +268,44 @@ namespace Newtonsoft.Json.Tests.Serialization
|
|||||||
Assert.IsTrue(JToken.DeepEquals(c.ExtensionData, c2.ExtensionData));
|
Assert.IsTrue(JToken.DeepEquals(c.ExtensionData, c2.ExtensionData));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class BaseClass
|
||||||
|
{
|
||||||
|
internal bool IsTransient { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class ChildClass : BaseClass
|
||||||
|
{
|
||||||
|
public new bool IsTransient { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void NewProperty()
|
||||||
|
{
|
||||||
|
Assert.AreEqual(@"{""IsTransient"":true}", JsonConvert.SerializeObject(new ChildClass { IsTransient = true }));
|
||||||
|
|
||||||
|
var childClass = JsonConvert.DeserializeObject<ChildClass>(@"{""IsTransient"":true}");
|
||||||
|
Assert.AreEqual(true, childClass.IsTransient);
|
||||||
|
}
|
||||||
|
|
||||||
|
public class BaseClassVirtual
|
||||||
|
{
|
||||||
|
internal virtual bool IsTransient { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class ChildClassVirtual : BaseClassVirtual
|
||||||
|
{
|
||||||
|
public virtual new bool IsTransient { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void NewPropertyVirtual()
|
||||||
|
{
|
||||||
|
Assert.AreEqual(@"{""IsTransient"":true}", JsonConvert.SerializeObject(new ChildClassVirtual { IsTransient = true }));
|
||||||
|
|
||||||
|
var childClass = JsonConvert.DeserializeObject<ChildClassVirtual>(@"{""IsTransient"":true}");
|
||||||
|
Assert.AreEqual(true, childClass.IsTransient);
|
||||||
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void JsonSerializerProperties()
|
public void JsonSerializerProperties()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -91,5 +91,5 @@ using System.Security;
|
|||||||
// by using the '*' as shown below:
|
// by using the '*' as shown below:
|
||||||
|
|
||||||
[assembly: AssemblyVersion("6.0.0.0")]
|
[assembly: AssemblyVersion("6.0.0.0")]
|
||||||
[assembly: AssemblyFileVersion("6.0.1.17109")]
|
[assembly: AssemblyFileVersion("6.0.1.17115")]
|
||||||
[assembly: CLSCompliant(true)]
|
[assembly: CLSCompliant(true)]
|
||||||
|
|||||||
@@ -855,6 +855,10 @@ namespace Newtonsoft.Json.Utilities
|
|||||||
initialProperties.Add(subTypeProperty);
|
initialProperties.Add(subTypeProperty);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
|
PropertyInfo childProperty = initialProperties[index];
|
||||||
|
// don't replace public child with private base
|
||||||
|
if (!IsPublic(childProperty))
|
||||||
{
|
{
|
||||||
// replace nonpublic properties for a child, but gotten from
|
// replace nonpublic properties for a child, but gotten from
|
||||||
// the parent with the one from the child
|
// the parent with the one from the child
|
||||||
@@ -862,6 +866,7 @@ namespace Newtonsoft.Json.Utilities
|
|||||||
initialProperties[index] = subTypeProperty;
|
initialProperties[index] = subTypeProperty;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (!subTypeProperty.IsVirtual())
|
if (!subTypeProperty.IsVirtual())
|
||||||
|
|||||||
Reference in New Issue
Block a user