Make JSON support required properties (#72937)
authorKrzysztof Wicher <kwicher@microsoft.com>
Fri, 29 Jul 2022 08:06:08 +0000 (10:06 +0200)
committerGitHub <noreply@github.com>
Fri, 29 Jul 2022 08:06:08 +0000 (10:06 +0200)
commit9b63001fc6371ec788af3faf964136d4bd138c8f
tree26c469318844be2af3e770dd99e0b7a3c6cc41a3
parentb6115b0041222802a5693ed412efcdac1ab091f7
Make JSON support required properties (#72937)

* Throw exception when 'required' keyword used but ctor does not have 'SetsRequiredMembers'

* Support required keyword (and internal IsRequired)

* remove local variable (forgot to press Save All)

* revert added namespaces in two files

* Apply feedback

* apply second round of feedback (minus HashSet optimization)

* Use BitArray rather than HashSet

* simplify validation code

* Truncate the message if too long, flip meaning of bit array bits

* remove default value, add description for BitArray

* for compiler attributes check for full type name rather than using typeof on net7.0
17 files changed:
src/libraries/System.Text.Json/src/Resources/Strings.resx
src/libraries/System.Text.Json/src/System/ReflectionExtensions.cs
src/libraries/System.Text.Json/src/System/Text/Json/JsonHelpers.cs
src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Object/ObjectDefaultConverter.cs
src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Object/ObjectWithParameterizedConstructorConverter.Large.cs
src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Object/ObjectWithParameterizedConstructorConverter.Small.cs
src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Object/ObjectWithParameterizedConstructorConverter.cs
src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Read.HandlePropertyName.cs
src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/JsonParameterInfo.cs
src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/JsonPropertyInfo.cs
src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/JsonPropertyInfoOfT.cs
src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/JsonTypeInfo.cs
src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/ReflectionJsonTypeInfoOfT.cs
src/libraries/System.Text.Json/src/System/Text/Json/Serialization/ReadStackFrame.cs
src/libraries/System.Text.Json/src/System/Text/Json/ThrowHelper.Serialization.cs
src/libraries/System.Text.Json/tests/System.Text.Json.Tests/Serialization/RequiredKeywordTests.cs [new file with mode: 0644]
src/libraries/System.Text.Json/tests/System.Text.Json.Tests/System.Text.Json.Tests.csproj