JsonInheritanceConverter.Read:
hasDiscriminator ? discriminator.GetString(): Possible null reference argument for parameter 'discriminatorValue' in 'Type JsonInheritanceConverter.GetDiscriminatorType(JsonElement jObject, Type objectType, string discriminatorValue)'.
return (TBase)System.Text.Json.JsonSerializer.Deserialize(bufferWriter.ToArray(), subtype, options);: Converting null literal or possible null value to non-nullable type.
JsonInheritanceConverter.Write:
GetDiscriminatorValue(value.GetType()): Dereference of a possibly null reference.
Required fixes:GetDiscriminatorType: string discriminatorValue -> string? discriminatorValueGetObjectSubtype: string discriminatorValue -> string? discriminatorValueRead: return type TBase?JsonInheritanceConverter: add where TBase : class constraint
When nullable reference types are allowed in the project containing the generated code, several JsonInheritanceConverter related warnings are raised.
Command: openapi2csclient JsonLibrary: SystemTextJson NSwag version: 13.15.10.0
JsonInheritanceConverter.Read
:hasDiscriminator ? discriminator.GetString()
: Possible null reference argument for parameter 'discriminatorValue' in 'Type JsonInheritanceConverterreturn (TBase)System.Text.Json.JsonSerializer.Deserialize(bufferWriter.ToArray(), subtype, options);
: Converting null literal or possible null value to non-nullable type.JsonInheritanceConverter.Write
:GetDiscriminatorValue(value.GetType())
: Dereference of a possibly null reference.Required fixes:
GetDiscriminatorType
:string discriminatorValue
->string? discriminatorValue
GetObjectSubtype
:string discriminatorValue
->string? discriminatorValue
Read
: return typeTBase?
JsonInheritanceConverter
: addwhere TBase : class
constraint