VerifyTests/Verify

Different behavior between Verify.SystemJson and Verify.NewtonsoftJson for empty property

Closed this issue · 3 comments

Describe the bug

Use the following with Verify.SystemJson:

[Fact]
public Task TestEmpty() =>
    Verify(JsonNode.Parse("""
    {
        "empty":{}
    }
    """));

It results in:

{
  empty: {}
}

Use the following with Verify.NewtonsoftJson:

[Fact]
public Task TestEmpty() =>
    Verify(JObject.Parse("""
{
    "empty":{}
}
"""));

It results in:

{
  {}
}

The problem seems to be happening when

settings.Serializer.Serialize(this, value);
is called with an empty collection.

It would be nice if Verify.NewtonsoftJson could produce the same result as Verify.SystemJson. I checked the settings and I don't see an option to fix that. Perhaps I missed it?

try this

[Fact]
public Task TestEmpty() =>
    Verify(
        JObject.Parse(
            """
            {
                "empty":{}
            }
            """))
        .DontIgnoreEmptyCollections();

or

[ModuleInitializer]
public static void Initialize() =>
    VerifierSettings.DontIgnoreEmptyCollections();

Oh, I see. OK thanks. I was only looking at the JSON settings.