File tree Expand file tree Collapse file tree 3 files changed +31
-1
lines changed
src/libraries/System.Text.Json
src/System/Text/Json/Serialization/Metadata
System.Text.Json.SourceGeneration.Tests/Serialization Expand file tree Collapse file tree 3 files changed +31
-1
lines changed Original file line number Diff line number Diff line change @@ -1209,7 +1209,8 @@ internal void ConfigureConstructorParameters()
12091209 continue ;
12101210 }
12111211
1212- ParameterLookupKey paramKey = new ( propertyInfo . PropertyType , propertyInfo . Name ) ;
1212+ string propertyName = propertyInfo . MemberName ?? propertyInfo . Name ;
1213+ ParameterLookupKey paramKey = new ( propertyInfo . PropertyType , propertyName ) ;
12131214 if ( ! parameterIndex . TryAdd ( paramKey , parameterInfo ) )
12141215 {
12151216 // Multiple object properties cannot bind to the same constructor parameter.
Original file line number Diff line number Diff line change @@ -1668,5 +1668,32 @@ public async Task RespectRequiredConstructorParameters_NoParameterMissing_Succee
16681668 Assert . Equal ( 2 , result . Y ) ;
16691669 Assert . Equal ( 3 , result . Z ) ;
16701670 }
1671+
1672+ [ Fact ]
1673+ public async Task ClassWithConflictingCaseInsensitiveProperties_Succeeds_When_CaseSensitive ( )
1674+ {
1675+ // Regression test for https://github.com/dotnet/runtime/issues/109768
1676+
1677+ string json = """{"a": "lower", "A": "upper"}""" ;
1678+ ClassWithConflictingCaseInsensitiveProperties result = await Serializer . DeserializeWrapper < ClassWithConflictingCaseInsensitiveProperties > ( json ) ;
1679+ Assert . Equal ( "lower" , result . From ) ;
1680+ Assert . Equal ( "upper" , result . To ) ;
1681+ }
1682+
1683+ public class ClassWithConflictingCaseInsensitiveProperties
1684+ {
1685+ [ JsonPropertyName ( "a" ) ]
1686+ public string From { get ; set ; }
1687+
1688+ [ JsonPropertyName ( "A" ) ]
1689+ public string To { get ; set ; }
1690+
1691+ [ JsonConstructor ]
1692+ public ClassWithConflictingCaseInsensitiveProperties ( string from , string to )
1693+ {
1694+ From = from ;
1695+ To = to ;
1696+ }
1697+ }
16711698 }
16721699}
Original file line number Diff line number Diff line change @@ -154,6 +154,7 @@ protected ConstructorTests_Metadata(JsonSerializerWrapper stringWrapper)
154154 [ JsonSerializable ( typeof ( TypeWithEnumParameters ) ) ]
155155 [ JsonSerializable ( typeof ( ClassWithIgnoredPropertyDefaultParam ) ) ]
156156 [ JsonSerializable ( typeof ( ClassWithCustomConverterOnCtorParameter ) ) ]
157+ [ JsonSerializable ( typeof ( ClassWithConflictingCaseInsensitiveProperties ) ) ]
157158 internal sealed partial class ConstructorTestsContext_Metadata : JsonSerializerContext
158159 {
159160 }
@@ -303,6 +304,7 @@ public ConstructorTests_Default(JsonSerializerWrapper jsonSerializer) : base(jso
303304 [ JsonSerializable ( typeof ( TypeWithEnumParameters ) ) ]
304305 [ JsonSerializable ( typeof ( ClassWithIgnoredPropertyDefaultParam ) ) ]
305306 [ JsonSerializable ( typeof ( ClassWithCustomConverterOnCtorParameter ) ) ]
307+ [ JsonSerializable ( typeof ( ClassWithConflictingCaseInsensitiveProperties ) ) ]
306308 internal sealed partial class ConstructorTestsContext_Default : JsonSerializerContext
307309 {
308310 }
You can’t perform that action at this time.
0 commit comments