|
@@ -12,15 +12,19 @@ namespace Jellyfin.Extensions.Json.Converters
|
|
|
{
|
|
|
/// <inheritdoc />
|
|
|
public override Guid Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
|
|
- {
|
|
|
- var guidStr = reader.GetString();
|
|
|
- return guidStr == null ? Guid.Empty : new Guid(guidStr);
|
|
|
- }
|
|
|
+ => reader.TokenType == JsonTokenType.Null
|
|
|
+ ? Guid.Empty
|
|
|
+ : ReadInternal(ref reader);
|
|
|
+
|
|
|
+ // TODO: optimize by parsing the UTF8 bytes instead of converting to string first
|
|
|
+ internal static Guid ReadInternal(ref Utf8JsonReader reader)
|
|
|
+ => Guid.Parse(reader.GetString()!); // null got handled higher up the call stack
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
public override void Write(Utf8JsonWriter writer, Guid value, JsonSerializerOptions options)
|
|
|
- {
|
|
|
- writer.WriteStringValue(value.ToString("N", CultureInfo.InvariantCulture));
|
|
|
- }
|
|
|
+ => WriteInternal(writer, value);
|
|
|
+
|
|
|
+ internal static void WriteInternal(Utf8JsonWriter writer, Guid value)
|
|
|
+ => writer.WriteStringValue(value.ToString("N", CultureInfo.InvariantCulture));
|
|
|
}
|
|
|
}
|