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
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,8 @@ private void AddSource(string fileName, string source, bool isRootContextDef = f
bool isInGlobalNamespace = @namespace == JsonConstants.GlobalNamespaceValue;

StringBuilder sb = new(@"// <auto-generated/>
#nullable enable
#nullable enable annotations
#nullable disable warnings

// Suppress warnings about [Obsolete] member usage in generated code.
#pragma warning disable CS0618");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,21 @@ public static void SupportsGenericParameterWithCustomConverterFactory()
Assert.Equal(@"[""Cee""]", json);
}

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

ClassWithStringValues obj = new()
{
StringValuesProperty = new(new[] { "abc", "def" })
};

string json = JsonSerializer.Serialize(obj, options);
Assert.Equal("""{"StringValuesProperty":["abc","def"]}""", json);
}

[JsonConverter(typeof(JsonStringEnumConverter))]
public enum TestEnum
{
Expand All @@ -394,7 +409,11 @@ internal partial class GenericParameterWithCustomConverterFactoryContext : JsonS
[JsonSerializable(typeof(ClassWithPocoListDictionaryAndNullable))]
internal partial class ClassWithPocoListDictionaryAndNullablePropertyContext : JsonSerializerContext
{
}

[JsonSerializable(typeof(ClassWithStringValues))]
internal partial class ClassWithStringValuesContext : JsonSerializerContext
{
}

internal class ClassWithPocoListDictionaryAndNullable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@
<Compile Include="$(CoreLibSharedDir)System\Diagnostics\CodeAnalysis\DynamicallyAccessedMemberTypes.cs" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="$(LibrariesProjectRoot)Microsoft.Extensions.Primitives\src\Microsoft.Extensions.Primitives.csproj" />
</ItemGroup>

<Target Name="FixIncrementalCoreCompileWithAnalyzers" BeforeTargets="CoreCompile">
<ItemGroup>
<CustomAdditionalCompileInputs Include="@(Analyzer)" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System.Collections.Generic;
using System.Text.Json.Serialization;
using Microsoft.Extensions.Primitives;

namespace System.Text.Json.SourceGeneration.Tests.RepeatedTypes
{
Expand Down Expand Up @@ -275,4 +276,9 @@ public class PublicTestClass
{
internal class InternalNestedClass { }
}

public sealed class ClassWithStringValues
{
public StringValues StringValuesProperty { get; set; }
}
}