The System.Text.Json serializer for Guid backed objects throws System.ArgumentNullException instead of System.Text.Json.JsonException when the property value is null #581
Labels
bug
Something isn't working
Describe the bug
System.Text.Json
expects custom converters to throwJsonException
orNotSupportedException
. With aGuid
backedValueObject
, the generated converter will throwArgumentNullException
for when presented with anull
value in the raw JSON. This happens because the generated code calls intoGuid.Parse
instead ofGuid.TryParse
and then handling the result.This is a problem because throwing an
ArgumentNullException
here will cause ASP.NET WebApi endpoints to generate a 500 response instead of a 400. A minimal repro to generate theArgumentNullException
is included in the steps to reproduce.Steps to reproduce
Expected behaviour
The expectation is for a
System.Text.Json.Serialization.JsonConverter
to throwSystem.Text.Json.JsonException
. Manually changing the generated read method to something like this generates the expected behavior and triggers ASP.NET to return a 400.The text was updated successfully, but these errors were encountered: