diff --git a/SystemTextJsonPatch.Tests/IntegrationTests/NestedObjectIntegrationTest.cs b/SystemTextJsonPatch.Tests/IntegrationTests/NestedObjectIntegrationTest.cs index 23bedae..90e9b40 100644 --- a/SystemTextJsonPatch.Tests/IntegrationTests/NestedObjectIntegrationTest.cs +++ b/SystemTextJsonPatch.Tests/IntegrationTests/NestedObjectIntegrationTest.cs @@ -2,6 +2,7 @@ using System.Dynamic; using System.Text.Json; using SystemTextJsonPatch.Exceptions; +using SystemTextJsonPatch.Operations; using Xunit; namespace SystemTextJsonPatch.IntegrationTests; @@ -56,6 +57,39 @@ public void ReplaceNestedObjectWithSerialization() // Assert Assert.Equal("B", targetObject.NestedObject.StringProperty); } + +#if NET8_0 + + [Fact] + public void ReplaceNestedObjectWithPlainStrings() + { + // Arrange + var targetObject = new SimpleObjectWithNestedObject() + { + IntegerValue = 1, + NestedObject = null + }; + var options = new JsonSerializerOptions() + { + PropertyNamingPolicy = JsonNamingPolicy.SnakeCaseLower + }; + + var newNested = new NestedObject { StringProperty = "B" }; + var patchDocument = new JsonPatchDocument(); + patchDocument.Operations.Add(new Operation("replace", "/nested_object", JsonSerializer.Serialize(newNested, options))); + patchDocument.Options = options; + + var serialized = JsonSerializer.Serialize(patchDocument, options); + var deserialized = JsonSerializer.Deserialize>(serialized, options); + + // Act + deserialized.ApplyTo(targetObject); + + // Assert + Assert.Equal("B", targetObject.NestedObject.StringProperty); + } + +#endif [Fact] public void TestStringPropertyInNestedObject()