NJsonSchema icon indicating copy to clipboard operation
NJsonSchema copied to clipboard

fixes #1728 return null when subType is not found, fixes Stackoverflow exception

Open ryanheath opened this issue 5 months ago • 0 comments

Fixes #1728

I do not know how to test it. The generated code in the liquid file is not the same as the 'real' NJsonSchema.Converters.JsonInheritanceConverter<TBase>, which has tests.

Also the 'real' code of GetObjectSubtype returns a null value when subType is not found. so the fix got to be right! ;)

private static Type? GetObjectSubtype(Type baseType, string discriminatorValue)
{
    var jsonInheritanceAttributes = baseType
        .GetTypeInfo()
        .GetCustomAttributes(true)
        .OfType<JsonInheritanceAttribute>();

    return jsonInheritanceAttributes.SingleOrDefault(a => a.Key == discriminatorValue)?.Type;
}

ryanheath avatar Sep 07 '24 13:09 ryanheath