Fixes exception when converting UDIs in a PropertyValueConverter (#20011)

* Changed to use TryParse

* Changed to be a null check instead

* Update to "is false" syntax and add unit tests.

---------

Co-authored-by: Andy Butland <abutland73@gmail.com>
This commit is contained in:
Aaron
2025-09-05 07:19:06 +01:00
committed by GitHub
parent da05e280af
commit f06da1c7fa
3 changed files with 97 additions and 13 deletions

View File

@@ -15,9 +15,14 @@ public sealed class JsonUdiConverter : JsonConverter<Udi>
/// <inheritdoc />
public override Udi? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
=> reader.GetString() is string value
? UdiParser.Parse(value)
: null;
{
if (reader.GetString() is string value && string.IsNullOrWhiteSpace(value) is false)
{
return UdiParser.Parse(value);
}
return null;
}
/// <inheritdoc />
public override void Write(Utf8JsonWriter writer, Udi value, JsonSerializerOptions options)