NJsonSchema
NJsonSchema copied to clipboard
fixes #1728 return null when subType is not found, fixes Stackoverflow exception
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;
}