Skip to content

Commit

Permalink
Reinstante _converterIsExternalAndPolymorphic
Browse files Browse the repository at this point in the history
  • Loading branch information
eiriktsarpalis committed Jul 1, 2022
1 parent b4b8e0c commit dfec188
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ internal void EnsureConfigured()
_isConfigured = true;
}

internal void Configure()
internal virtual void Configure()
{
Debug.Assert(ParentTypeInfo != null, "We should have ensured parent is assigned in JsonTypeInfo");
DeclaringTypeNumberHandling = ParentTypeInfo.NumberHandling;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ namespace System.Text.Json.Serialization.Metadata
/// or a type's converter, if the current instance is a <see cref="JsonTypeInfo.PropertyInfoForTypeInfo"/>.
internal sealed class JsonPropertyInfo<T> : JsonPropertyInfo
{
/// <summary>
/// Returns true if the property's converter is external (a user's custom converter)
/// and the type to convert is not the same as the declared property type (polymorphic).
/// Used to determine whether to perform additional validation on the value returned by the
/// converter on deserialization.
/// </summary>
private bool _converterIsExternalAndPolymorphic;

// Since a converter's TypeToConvert (which is the T value in this type) can be different than
// the property's type, we track that and whether the property type can be null.
private readonly bool _propertyTypeEqualsTypeToConvert;
Expand Down Expand Up @@ -190,6 +198,16 @@ internal JsonPropertyInfo(JsonSerializerOptions options, JsonPropertyInfoValues<
NumberHandling = propertyInfo.NumberHandling;
}

internal override void Configure()
{
base.Configure();

if (!IsForTypeInfo && !IsIgnored)
{
_converterIsExternalAndPolymorphic = !EffectiveConverter.IsInternalConverter && PropertyType != EffectiveConverter.TypeToConvert;
}
}

private protected override void DetermineEffectiveConverter()
{
JsonConverter? customConverter = CustomConverter;
Expand Down

0 comments on commit dfec188

Please sign in to comment.