'Can .net web api throw exception for request with invalid Enum other than set the request to null?

we have a web api in .net 6

public async Task<MyResult> SeriesDataV21([FromBody] SeriesDataRequest seriesDataRequest)
{
}

The request object SeriesDataRequest has an enum and I added a converter to accept string. option.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter(JsonNamingPolicy.CamelCase));

However, if the enum in the request is not valid, the seriesDataRequest is passed in as null. Is there a way to ask .net 6 to directly throwing an exception? As we have multiple endpoints and it is much easier if an exception got thrown out by .net other than we manually check the request everywhere.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source