Drop the extra MruCache and resolve public fields lazily into the existing cache entry

This commit is contained in:
dualfroz committed 2026-10-11 18:59:41 +02:00
1 parent 7c96e99fb3
commit eb43ff4c98
2 files changed
+46 -20

No files matched your search

@@ -246,6 +246,24 @@ namespace NLog.UnitTests.Targets
Assert.Equal(@"{""Name"":""John"",""Age"":42}", withFieldsAgain.ToString());
}
[Fact]
public void IncludePublicFields_SameTypeWithoutOptionFirst_StillSerializesFieldsLater()
{
var testObject = new ClassWithOnlyFields { Name = "John", Age = 42 };
var jsonSerializer = new DefaultJsonSerializer(null);
var withoutFields = new StringBuilder();
jsonSerializer.SerializeObject(testObject, withoutFields, new JsonSerializeOptions { IncludePublicFields = false });
var withFields = new StringBuilder();
jsonSerializer.SerializeObject(testObject, withFields, new JsonSerializeOptions { IncludePublicFields = true });
var withoutFieldsAgain = new StringBuilder();
jsonSerializer.SerializeObject(testObject, withoutFieldsAgain, new JsonSerializeOptions { IncludePublicFields = false });
Assert.DoesNotContain(@"""Age"":42", withoutFields.ToString());
Assert.Equal(@"{""Name"":""John"",""Age"":42}", withFields.ToString());
Assert.Equal(withoutFields.ToString(), withoutFieldsAgain.ToString());
}
[Fact]
public void IncludePublicFields_ShadowedField_IsWrittenOnce()
{