title: Dart json encode map with custom object as key
body: <p>I have started working with dart . I have the following scenario. In my application I have a Map which has a Peptide object as key for every entry and a num as value .</p>
  <p>I am trying to encode this map as json but I get
  <code>Converting object to an encodable object failed: _LinkedHashMap len:2</code></p>
  <p>Here is my code:</p>
  <pre class="lang-dart prettyprint-override"><code>import 'dart:convert';
  
  class Peptide {
    String name;
    Peptide({required this.name});
  }
  
  void main() {
    Map&lt;Peptide, num&gt; foo = {Peptide(name: &quot;a&quot;): 0.5, Peptide(name: &quot;b&quot;): 0.3};
    print(json.encode(foo));
  }
  </code></pre>
  <p>Any ideas how can I approach this issue?</p>