Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support strong typed JsonStringEnumConverter in HasStringEnumConverter #1741

Open
GZTimeWalker opened this issue Nov 19, 2024 · 0 comments
Open

Comments

@GZTimeWalker
Copy link

currently, the HasStringEnumConverter will ignore strong typed JsonStringEnumConverter like JsonStringEnumConverter<TEnum>

private static bool HasStringEnumConverter(ContextualType contextualType)
{
dynamic? jsonConverterAttribute = contextualType
.GetContextOrTypeAttributes(true)?
.FirstOrDefault(a => a.GetType().Name == "JsonConverterAttribute");
if (jsonConverterAttribute != null && ObjectExtensions.HasProperty(jsonConverterAttribute, "ConverterType"))
{
var converterType = jsonConverterAttribute?.ConverterType as Type;
if (converterType != null)
{
return converterType.IsAssignableToTypeName("StringEnumConverter", TypeNameStyle.Name) ||
converterType.IsAssignableToTypeName("System.Text.Json.Serialization.JsonStringEnumConverter", TypeNameStyle.FullName);
}
}
return false;
}

The attribute has the ConverType with:

FullName: System.Text.Json.Serialization.JsonStringEnumConverter`1[[...]
Name: JsonStringEnumConverter`1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant