Merge pull request #4730 from crobibero/base-item-dto-guid-nullable

Don't serialize empty GUID to null
This commit is contained in:
Claus Vium
2020-12-08 18:22:18 +01:00
committed by GitHub
4 changed files with 11 additions and 19 deletions

View File

@@ -13,21 +13,13 @@ namespace MediaBrowser.Common.Json.Converters
public override Guid Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
var guidStr = reader.GetString();
return guidStr == null ? Guid.Empty : new Guid(guidStr);
}
/// <inheritdoc />
public override void Write(Utf8JsonWriter writer, Guid value, JsonSerializerOptions options)
{
if (value == Guid.Empty)
{
writer.WriteNullValue();
}
else
{
writer.WriteStringValue(value);
}
writer.WriteStringValue(value);
}
}
}