Skip to content

Commit

Permalink
Add testcase for #61734
Browse files Browse the repository at this point in the history
  • Loading branch information
krwq authored and github-actions committed Aug 31, 2022
1 parent b7a7c94 commit 480af47
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ private void AddSource(string fileName, string source, bool isRootContextDef = f
bool isInGlobalNamespace = @namespace == JsonConstants.GlobalNamespaceValue;

StringBuilder sb = new(@"// <auto-generated/>
#nullable enable annotations
#nullable disable warnings
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,22 @@ public static void ClassWithStringValuesRoundtrips()
Assert.Equal("""{"StringValuesProperty":["abc","def"]}""", json);
}

// Regression test for https://github.com/dotnet/runtime/issues/61734
[Fact]
public static void ClassWithDictionaryPropertyRoundtrips()
{
JsonSerializerOptions options = ClassWithDictionaryPropertyContext.Default.Options;

ClassWithDictionaryProperty obj = new(new Dictionary<string, object?>()
{
["foo"] = "bar",
["test"] = "baz",
});

string json = JsonSerializer.Serialize(obj, options);
Assert.Equal("""{"DictionaryProperty":{"foo":"bar","test":"baz"}}""", json);
}

[JsonConverter(typeof(JsonStringEnumConverter))]
public enum TestEnum
{
Expand All @@ -416,6 +432,11 @@ internal partial class ClassWithStringValuesContext : JsonSerializerContext
{
}

[JsonSerializable(typeof(ClassWithDictionaryProperty))]
internal partial class ClassWithDictionaryPropertyContext : JsonSerializerContext
{
}

internal class ClassWithPocoListDictionaryAndNullable
{
public uint UIntProperty { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,4 +281,10 @@ public sealed class ClassWithStringValues
{
public StringValues StringValuesProperty { get; set; }
}

public class ClassWithDictionaryProperty
{
public ClassWithDictionaryProperty(Dictionary<string, object?> property) => DictionaryProperty = property;
public Dictionary<string, object?> DictionaryProperty { get; }
}
}

0 comments on commit 480af47

Please sign in to comment.