0

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.

daxu
  • 3,514
  • 5
  • 38
  • 76
  • If I write a test to deserialize this using JsonSerializer.Deserialize, exception does throw. So not sure why my request will see null. – daxu Mar 07 '22 at 11:00
  • Since `JsonSerializer.Deserialize()` throws, the exception must be getting swallowed at some higher level in the web API framework. You might rewrite and retag your question to address that problem because as it is this doesn't look to be a problem at the [tag:.net-6.0] level. – dbc Mar 07 '22 at 15:21

0 Answers0