diff --git a/Src/Newtonsoft.Json.Tests/Serialization/JsonSerializerTest.cs b/Src/Newtonsoft.Json.Tests/Serialization/JsonSerializerTest.cs index 805bcfdf..26190d2f 100644 --- a/Src/Newtonsoft.Json.Tests/Serialization/JsonSerializerTest.cs +++ b/Src/Newtonsoft.Json.Tests/Serialization/JsonSerializerTest.cs @@ -4530,7 +4530,22 @@ Path '', line 1, position 1."); { string json = @"{""First"":""First"",""Second"":2,""Ignored"":{""Name"":""James""},""AdditionalContent"":{""LOL"":true}}"; - ConstructorCompexIgnoredProperty cc = JsonConvert.DeserializeObject(json); + var cc = JsonConvert.DeserializeObject(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( + json, new JsonSerializerSettings + { + MissingMemberHandling = MissingMemberHandling.Error + }); Assert.AreEqual("First", cc.First); Assert.AreEqual(2, cc.Second); Assert.AreEqual(null, cc.Ignored); @@ -7965,4 +7980,4 @@ This is just junk, though."; "Unexpected character encountered while parsing value: ,. Path 'E', line 1, position 36."); } } -} \ No newline at end of file +} diff --git a/Src/Newtonsoft.Json/Serialization/JsonSerializerInternalReader.cs b/Src/Newtonsoft.Json/Serialization/JsonSerializerInternalReader.cs index 97229a1b..64c921dc 100644 --- a/Src/Newtonsoft.Json/Serialization/JsonSerializerInternalReader.cs +++ b/Src/Newtonsoft.Json/Serialization/JsonSerializerInternalReader.cs @@ -2201,30 +2201,33 @@ namespace Newtonsoft.Json.Serialization propertyValues.Add(creatorPropertyContext); JsonProperty? property = creatorPropertyContext.ConstructorProperty ?? creatorPropertyContext.Property; - if (property != null && !property.Ignored) + if (property != null) { - if (property.PropertyContract == null) + if (!property.Ignored) { - property.PropertyContract = GetContractSafe(property.PropertyType); - } + if (property.PropertyContract == null) + { + property.PropertyContract = GetContractSafe(property.PropertyType); + } - JsonConverter? propertyConverter = GetConverter(property.PropertyContract, property.Converter, contract, containerProperty); + JsonConverter? propertyConverter = GetConverter(property.PropertyContract, property.Converter, contract, containerProperty); - if (!reader.ReadForType(property.PropertyContract, propertyConverter != null)) - { - throw JsonSerializationException.Create(reader, "Unexpected end when setting {0}'s value.".FormatWith(CultureInfo.InvariantCulture, memberName)); - } + if (!reader.ReadForType(property.PropertyContract, propertyConverter != null)) + { + throw JsonSerializationException.Create(reader, "Unexpected end when setting {0}'s value.".FormatWith(CultureInfo.InvariantCulture, memberName)); + } - if (propertyConverter != null && propertyConverter.CanRead) - { - creatorPropertyContext.Value = DeserializeConvertable(propertyConverter, reader, property.PropertyType!, null); + if (propertyConverter != null && propertyConverter.CanRead) + { + creatorPropertyContext.Value = DeserializeConvertable(propertyConverter, reader, property.PropertyType!, null); + } + else + { + creatorPropertyContext.Value = CreateValueInternal(reader, property.PropertyType, property.PropertyContract, property, contract, containerProperty, null); + } + + continue; } - else - { - creatorPropertyContext.Value = CreateValueInternal(reader, property.PropertyType, property.PropertyContract, property, contract, containerProperty, null); - } - - continue; } else {