You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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());
}
The text was updated successfully, but these errors were encountered:
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 overrideWriteAsPropertyName
andReadAsPropertyName
. 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.The text was updated successfully, but these errors were encountered: