Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Utar94 committed Dec 21, 2024
1 parent 3139f36 commit 0fc35df
Showing 1 changed file with 11 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Logitar.Identity.Core;
using System.Diagnostics.CodeAnalysis;
using System.Text.Json;
using System.Text.Json.Serialization;

Expand All @@ -11,8 +12,18 @@ public class IdentifierConverter : JsonConverter<Identifier>
return Identifier.TryCreate(reader.GetString());
}

public override Identifier ReadAsPropertyName(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
return Read(ref reader, typeToConvert, options) ?? throw new InvalidOperationException("The identifier could not be read.");
}

public override void Write(Utf8JsonWriter writer, Identifier identifier, JsonSerializerOptions options)
{
writer.WriteStringValue(identifier.Value);
}

public override void WriteAsPropertyName(Utf8JsonWriter writer, [DisallowNull] Identifier identifier, JsonSerializerOptions options)
{
writer.WritePropertyName(identifier.Value);
}
}

0 comments on commit 0fc35df

Please sign in to comment.