I have the following class, that I use as a key in a dictionary:
public class MyClass
{
private readonly string _property;
public My
Simpler, full solution, using a custom JsonConverter
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
public class CustomDictionaryConverter : JsonConverter
{
public override bool CanConvert(Type objectType) => objectType == typeof(Dictionary);
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
=> serializer.Serialize(writer, ((Dictionary)value).ToList());
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
=> serializer.Deserialize[]>(reader).ToDictionary(kv => kv.Key, kv => kv.Value);
}
Usage:
[JsonConverter(typeof(CustomDictionaryConverter))]
public Dictionary MyDictionary;