Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Add testcase for #61734
  • Loading branch information
krwq committed Aug 30, 2022
commit dd2aa95b381690a39a65faedc3e6d5c8efd18fbc
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; }
}
}