Closed hankovich closed 1 year ago
For now as a workaround I use the following hand-written converter
[StronglyTypedId(StronglyTypedIdBackingType.String, converters: StronglyTypedIdConverter.TypeConverter)]
[JsonConverter(typeof(GroupIdNewtonsoftJsonConverter))]
public partial struct GroupId
{
// workaround for https://github.com/andrewlock/StronglyTypedId/issues/83
private sealed class GroupIdNewtonsoftJsonConverter : JsonConverter
{
public override bool CanConvert(Type objectType)
{
return objectType == typeof(GroupId);
}
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
var id = (GroupId)value;
serializer.Serialize(writer, id.Value);
}
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
if (objectType == typeof(GroupId?))
{
var nullableString = serializer.Deserialize<string?>(reader);
if (nullableString == null)
{
return null!;
}
return new GroupId(nullableString);
}
return new GroupId(serializer.Deserialize<string>(reader));
}
}
}
Thanks for flagging this @hankovich, fixed in #94 using your suggestion 👍
@andrewlock are there any plans to release a new version that includes this fix?
Version of StronglyTypeId: 1.0.0-beta06 Version of Newtonsoft.Json: 13.0.1
Similar to #36