I have:
1)
Dictionary<MyClass, double>
2) elasticsearch 7
3) nest 7
I want to write my dictionary in elasticsearch database by:
client.IndexDocument(myDictionary).
I know, I can use
List<KeyValuePair<MyClass, double>>
But in my work I need use Dictionary.
You need to implement a type converter eg.MyClassConverter
for MyClass
and then add the attribute [TypeConverter(typeof(MyClassConverter))]
to the MyClass class declaration. This means that, instead of using the default ToString(), it will use the type convert that you define to serialize as you want.
The link "How to: Implement a Type Converter" shows how to create a type converter.
The SO link showing the answer is: Not ableTo Serialize Dictionary with Complex key using Json.net