Do not treat ignored field as missing member when deserializing from overriden json constructor (#2224)
This commit is contained in:
committed by
James Newton-King
parent
7c3d7f8da7
commit
9be95e0f6a
@@ -4530,7 +4530,22 @@ Path '', line 1, position 1.");
|
|||||||
{
|
{
|
||||||
string json = @"{""First"":""First"",""Second"":2,""Ignored"":{""Name"":""James""},""AdditionalContent"":{""LOL"":true}}";
|
string json = @"{""First"":""First"",""Second"":2,""Ignored"":{""Name"":""James""},""AdditionalContent"":{""LOL"":true}}";
|
||||||
|
|
||||||
ConstructorCompexIgnoredProperty cc = JsonConvert.DeserializeObject<ConstructorCompexIgnoredProperty>(json);
|
var cc = JsonConvert.DeserializeObject<ConstructorCompexIgnoredProperty>(json);
|
||||||
|
Assert.AreEqual("First", cc.First);
|
||||||
|
Assert.AreEqual(2, cc.Second);
|
||||||
|
Assert.AreEqual(null, cc.Ignored);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void DeserializeIgnoredPropertyInConstructorWithoutThrowingMissingMemberError()
|
||||||
|
{
|
||||||
|
string json = @"{""First"":""First"",""Second"":2,""Ignored"":{""Name"":""James""}}";
|
||||||
|
|
||||||
|
var cc = JsonConvert.DeserializeObject<ConstructorCompexIgnoredProperty>(
|
||||||
|
json, new JsonSerializerSettings
|
||||||
|
{
|
||||||
|
MissingMemberHandling = MissingMemberHandling.Error
|
||||||
|
});
|
||||||
Assert.AreEqual("First", cc.First);
|
Assert.AreEqual("First", cc.First);
|
||||||
Assert.AreEqual(2, cc.Second);
|
Assert.AreEqual(2, cc.Second);
|
||||||
Assert.AreEqual(null, cc.Ignored);
|
Assert.AreEqual(null, cc.Ignored);
|
||||||
|
|||||||
@@ -2201,7 +2201,9 @@ namespace Newtonsoft.Json.Serialization
|
|||||||
propertyValues.Add(creatorPropertyContext);
|
propertyValues.Add(creatorPropertyContext);
|
||||||
|
|
||||||
JsonProperty? property = creatorPropertyContext.ConstructorProperty ?? creatorPropertyContext.Property;
|
JsonProperty? property = creatorPropertyContext.ConstructorProperty ?? creatorPropertyContext.Property;
|
||||||
if (property != null && !property.Ignored)
|
if (property != null)
|
||||||
|
{
|
||||||
|
if (!property.Ignored)
|
||||||
{
|
{
|
||||||
if (property.PropertyContract == null)
|
if (property.PropertyContract == null)
|
||||||
{
|
{
|
||||||
@@ -2226,6 +2228,7 @@ namespace Newtonsoft.Json.Serialization
|
|||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (!reader.Read())
|
if (!reader.Read())
|
||||||
|
|||||||
Reference in New Issue
Block a user