Closed matthewvarley closed 4 months ago
Thanks very much for the feedback and repro. This has now been fixed - good spot! It will be in the next release, which is being built and should be available in an hour or so (once all the snapshot tests are finished! 🥱 )
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.