From 6a7f525b9caad77d9dd3f83af85c275826a708b7 Mon Sep 17 00:00:00 2001 From: John Morgan Date: Mon, 22 Sep 2025 08:52:07 +0100 Subject: [PATCH] Fix error message displayed when a property marked as DisallowNull is set to null --- Src/Newtonsoft.Json.Tests/Serialization/JsonSerializerTest.cs | 2 +- .../Serialization/JsonSerializerInternalReader.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Src/Newtonsoft.Json.Tests/Serialization/JsonSerializerTest.cs b/Src/Newtonsoft.Json.Tests/Serialization/JsonSerializerTest.cs index 35e885258d..dd17ea72ae 100644 --- a/Src/Newtonsoft.Json.Tests/Serialization/JsonSerializerTest.cs +++ b/Src/Newtonsoft.Json.Tests/Serialization/JsonSerializerTest.cs @@ -377,7 +377,7 @@ public void CoercedEmptyStringWithRequired() [Test] public void CoercedEmptyStringWithRequired_DisallowNull() { - ExceptionAssert.Throws(() => { JsonConvert.DeserializeObject("{requiredProperty:''}"); }, "Required property 'RequiredProperty' expects a non-null value. Path '', line 1, position 21."); + ExceptionAssert.Throws(() => { JsonConvert.DeserializeObject("{requiredProperty:''}"); }, "Property 'RequiredProperty' expects a non-null value. Path '', line 1, position 21."); } [Test] diff --git a/Src/Newtonsoft.Json/Serialization/JsonSerializerInternalReader.cs b/Src/Newtonsoft.Json/Serialization/JsonSerializerInternalReader.cs index d8c163d3e2..5b55c09acf 100644 --- a/Src/Newtonsoft.Json/Serialization/JsonSerializerInternalReader.cs +++ b/Src/Newtonsoft.Json/Serialization/JsonSerializerInternalReader.cs @@ -2632,7 +2632,7 @@ private void EndProcessProperty(object newObject, JsonReader reader, JsonObjectC } if (resolvedRequired == Required.DisallowNull) { - throw JsonSerializationException.Create(reader, "Required property '{0}' expects a non-null value.".FormatWith(CultureInfo.InvariantCulture, property.PropertyName)); + throw JsonSerializationException.Create(reader, "Property '{0}' expects a non-null value.".FormatWith(CultureInfo.InvariantCulture, property.PropertyName)); } break; }