Open
Description
The current implementation of the JsonConverter does not allow the use of Ulid as a dictionary key, resulting in an exception: The type 'System.Ulid' is not a supported dictionary key using converter of type 'Cysharp.Serialization.Json.UlidJsonConverter'.
The solution is to override WriteAsPropertyName
and ReadAsPropertyName
. Here is a no-nonsense extension of your converter class, but would be much better not having such an extension and just relying on yours.
public sealed class MyUlidJsonConverter : UlidJsonConverter
{
public override void WriteAsPropertyName(
Utf8JsonWriter writer,
Ulid ulid,
JsonSerializerOptions options) => writer.WritePropertyName(ulid.ToString());
public override Ulid ReadAsPropertyName(
ref Utf8JsonReader reader,
Type typeToConvert,
JsonSerializerOptions options) => Ulid.Parse(reader.GetString());
}
Metadata
Metadata
Assignees
Labels
No labels