-Fixed non-public base class properties being used instead of child class properties
This commit is contained in:
@@ -435,8 +435,8 @@ namespace Newtonsoft.Json.Tests.Linq.JsonPath
|
|||||||
[Test]
|
[Test]
|
||||||
public void EvaluateScan()
|
public void EvaluateScan()
|
||||||
{
|
{
|
||||||
JObject o1 = new JObject{ {"Name", 1} };
|
JObject o1 = new JObject { { "Name", 1 } };
|
||||||
JObject o2 = new JObject{ {"Name", 2} };
|
JObject o2 = new JObject { { "Name", 2 } };
|
||||||
JArray a = new JArray(o1, o2);
|
JArray a = new JArray(o1, o2);
|
||||||
|
|
||||||
IList<JToken> t = a.SelectTokens("$..Name").ToList();
|
IList<JToken> t = a.SelectTokens("$..Name").ToList();
|
||||||
@@ -655,7 +655,7 @@ namespace Newtonsoft.Json.Tests.Linq.JsonPath
|
|||||||
new JProperty("name", "The Rock"),
|
new JProperty("name", "The Rock"),
|
||||||
new JProperty("cast", new JArray(
|
new JProperty("cast", new JArray(
|
||||||
new JObject(new JProperty("name", "Nick Cage")))))
|
new JObject(new JProperty("name", "Nick Cage")))))
|
||||||
);
|
);
|
||||||
|
|
||||||
IList<JToken> t = a.SelectTokens("[?(@.cast[?(@.name=='Will Smith')])].name").ToList();
|
IList<JToken> t = a.SelectTokens("[?(@.cast[?(@.name=='Will Smith')])].name").ToList();
|
||||||
Assert.IsNotNull(t);
|
Assert.IsNotNull(t);
|
||||||
|
|||||||
@@ -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)]
|
||||||
|
|||||||
@@ -856,10 +856,15 @@ namespace Newtonsoft.Json.Utilities
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// replace nonpublic properties for a child, but gotten from
|
PropertyInfo childProperty = initialProperties[index];
|
||||||
// the parent with the one from the child
|
// don't replace public child with private base
|
||||||
// the property gotten from the child will have access to private getter/setter
|
if (!IsPublic(childProperty))
|
||||||
initialProperties[index] = subTypeProperty;
|
{
|
||||||
|
// replace nonpublic properties for a child, but gotten from
|
||||||
|
// the parent with the one from the child
|
||||||
|
// the property gotten from the child will have access to private getter/setter
|
||||||
|
initialProperties[index] = subTypeProperty;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
Reference in New Issue
Block a user