[JsonConverter(typeof(OptionConverter))]
public class Option
{
public string Value { get; set; }
}
public class P
{
static void Main()
{
var d = new Dictionary<Option, string> {{new Option{Value = "abc"}, "abc"}};
Console.WriteLine(JsonSerializer.Serialize(d,
new JsonSerializerOptions
{
Converters =
{
new DictionaryKeyToStringConverter()
}
}
));
}
}
Makes this code working: