Skip to content

Commit

Permalink
Remove types deriving from JsonTypeInfo<T> and mark as sealed. (#81306)
Browse files Browse the repository at this point in the history
* Remove types deriving from JsonTypeInfo<T> and mark as sealed.

* Rename the metadata resolution files.

* Address feedback

* Only sort properties if necessary.
  • Loading branch information
eiriktsarpalis committed Feb 2, 2023
1 parent 9e8d0a8 commit 6aa9f8b
Show file tree
Hide file tree
Showing 17 changed files with 498 additions and 614 deletions.
6 changes: 3 additions & 3 deletions src/libraries/System.Text.Json/gen/TypeGenerationSpec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ public bool TryFilterSerializableProps(

castingRequiredForProps = false;
serializableProperties = new Dictionary<string, PropertyGenerationSpec>();
Dictionary<string, PropertyGenerationSpec>? ignoredMembers = null;
HashSet<string>? ignoredMembers = null;

for (int i = 0; i < PropertyGenSpecList.Count; i++)
{
Expand Down Expand Up @@ -245,7 +245,7 @@ public bool TryFilterSerializableProps(
other.ClrName == memberName ||
// Was a property with the same CLR name ignored? That property hid the current property,
// thus, if it was ignored, the current property should be ignored too.
ignoredMembers?.ContainsKey(memberName) == true;
ignoredMembers?.Contains(memberName) == true;
}
else
{
Expand All @@ -271,7 +271,7 @@ public bool TryFilterSerializableProps(

if (propGenSpec.DefaultIgnoreCondition == JsonIgnoreCondition.Always)
{
(ignoredMembers ??= new()).Add(memberName, propGenSpec);
(ignoredMembers ??= new()).Add(memberName);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/libraries/System.Text.Json/ref/System.Text.Json.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1271,7 +1271,7 @@ public static partial class JsonTypeInfoResolver
{
public static System.Text.Json.Serialization.Metadata.IJsonTypeInfoResolver Combine(params System.Text.Json.Serialization.Metadata.IJsonTypeInfoResolver?[] resolvers) { throw null; }
}
public abstract partial class JsonTypeInfo<T> : System.Text.Json.Serialization.Metadata.JsonTypeInfo
public sealed partial class JsonTypeInfo<T> : System.Text.Json.Serialization.Metadata.JsonTypeInfo
{
internal JsonTypeInfo() { }
public new System.Func<T>? CreateObject { get { throw null; } set { } }
Expand Down
5 changes: 2 additions & 3 deletions src/libraries/System.Text.Json/src/System.Text.Json.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ The System.Text.Json library is built-in as part of the shared framework in .NET
<Compile Include="System\Text\Json\Serialization\JsonSerializerContext.cs" />
<Compile Include="System\Text\Json\Serialization\JsonUnknownDerivedTypeHandling.cs" />
<Compile Include="System\Text\Json\Serialization\Metadata\DefaultJsonTypeInfoResolver.Converters.cs" />
<Compile Include="System\Text\Json\Serialization\Metadata\DefaultJsonTypeInfoResolver.Helpers.cs" />
<Compile Include="System\Text\Json\Serialization\Metadata\DefaultJsonTypeInfoResolver.cs" />
<Compile Include="System\Text\Json\Serialization\Metadata\IJsonTypeInfoResolver.cs" />
<Compile Include="System\Text\Json\Serialization\Metadata\JsonDerivedType.cs" />
Expand All @@ -135,7 +136,6 @@ The System.Text.Json library is built-in as part of the shared framework in .NET
<Compile Include="System\Text\Json\Serialization\Metadata\JsonTypeInfoOfT.WriteHelpers.cs" />
<Compile Include="System\Text\Json\Serialization\Metadata\JsonTypeInfoResolver.cs" />
<Compile Include="System\Text\Json\Serialization\Metadata\JsonTypeInfoKind.cs" />
<Compile Include="System\Text\Json\Serialization\Metadata\CustomJsonTypeInfoOfT.cs" />
<Compile Include="System\Text\Json\Serialization\PolymorphicSerializationState.cs" />
<Compile Include="System\Text\Json\Writer\Utf8JsonWriterCache.cs" />
<Compile Include="System\Text\Json\Serialization\ReferenceEqualsWrapper.cs" />
Expand Down Expand Up @@ -249,6 +249,7 @@ The System.Text.Json library is built-in as part of the shared framework in .NET
<Compile Include="System\Text\Json\Serialization\Metadata\JsonCollectionInfoValuesOfTCollection.cs" />
<Compile Include="System\Text\Json\Serialization\Metadata\JsonMetadataServices.Collections.cs" />
<Compile Include="System\Text\Json\Serialization\Metadata\JsonMetadataServices.Converters.cs" />
<Compile Include="System\Text\Json\Serialization\Metadata\JsonMetadataServices.Helpers.cs" />
<Compile Include="System\Text\Json\Serialization\Metadata\JsonMetadataServices.cs" />
<Compile Include="System\Text\Json\Serialization\Metadata\JsonObjectInfoValuesOfT.cs" />
<Compile Include="System\Text\Json\Serialization\Metadata\JsonParameterInfoValues.cs" />
Expand All @@ -257,15 +258,13 @@ The System.Text.Json library is built-in as part of the shared framework in .NET
<Compile Include="System\Text\Json\Serialization\Metadata\JsonPropertyInfo.cs" />
<Compile Include="System\Text\Json\Serialization\Metadata\JsonPropertyInfoOfT.cs" />
<Compile Include="System\Text\Json\Serialization\Metadata\JsonPropertyInfoValuesOfT.cs" />
<Compile Include="System\Text\Json\Serialization\Metadata\SourceGenJsonTypeInfoOfT.cs" />
<Compile Include="System\Text\Json\Serialization\Metadata\JsonTypeInfoOfT.cs" />
<Compile Include="System\Text\Json\Serialization\Metadata\JsonTypeInfo.Cache.cs" />
<Compile Include="System\Text\Json\Serialization\Metadata\JsonTypeInfo.cs" />
<Compile Include="System\Text\Json\Serialization\Metadata\MemberAccessor.cs" />
<Compile Include="System\Text\Json\Serialization\Metadata\ParameterRef.cs" />
<Compile Include="System\Text\Json\Serialization\Metadata\PolymorphicTypeResolver.cs" />
<Compile Include="System\Text\Json\Serialization\Metadata\PropertyRef.cs" />
<Compile Include="System\Text\Json\Serialization\Metadata\ReflectionJsonTypeInfoOfT.cs" />
<Compile Include="System\Text\Json\Serialization\Metadata\ReflectionEmitCachingMemberAccessor.Cache.cs" />
<Compile Include="System\Text\Json\Serialization\Metadata\ReflectionEmitCachingMemberAccessor.cs" />
<Compile Include="System\Text\Json\Serialization\Metadata\ReflectionEmitMemberAccessor.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,16 +90,7 @@ internal virtual void ReadElementAndSetProperty(
throw new InvalidOperationException();
}

[RequiresDynamicCode(JsonSerializer.SerializationRequiresDynamicCodeMessage)]
[RequiresUnreferencedCode(JsonSerializer.SerializationUnreferencedCodeMessage)]
internal virtual JsonTypeInfo CreateReflectionJsonTypeInfo(JsonSerializerOptions options)
{
Debug.Fail("Should not be reachable.");

throw new InvalidOperationException();
}

internal virtual JsonTypeInfo CreateCustomJsonTypeInfo(JsonSerializerOptions options)
internal virtual JsonTypeInfo CreateJsonTypeInfo(JsonSerializerOptions options)
{
Debug.Fail("Should not be reachable.");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,9 @@ public override bool CanConvert(Type typeToConvert)

private protected override ConverterStrategy GetDefaultConverterStrategy() => ConverterStrategy.Value;

[RequiresDynamicCode(JsonSerializer.SerializationRequiresDynamicCodeMessage)]
[RequiresUnreferencedCode(JsonSerializer.SerializationUnreferencedCodeMessage)]
internal sealed override JsonTypeInfo CreateReflectionJsonTypeInfo(JsonSerializerOptions options)
internal sealed override JsonTypeInfo CreateJsonTypeInfo(JsonSerializerOptions options)
{
return new ReflectionJsonTypeInfo<T>(this, options);
}

internal sealed override JsonTypeInfo CreateCustomJsonTypeInfo(JsonSerializerOptions options)
{
return new CustomJsonTypeInfo<T>(this, options);
return new JsonTypeInfo<T>(this, options);
}

internal sealed override JsonParameterInfo CreateJsonParameterInfo()
Expand Down

This file was deleted.

Loading

0 comments on commit 6aa9f8b

Please sign in to comment.