title: jsonEncode doesn't work with enum extensions; is there a workaround?
body: <p>In Dart (2.15.0), I'm trying to use jsonEncode with enums by defining a toJson method. And it's not working.</p>
  <pre class="lang-dart prettyprint-override"><code>import 'dart:convert';
  
  enum Day { monday, tuesday }
  
  extension ParseToJsonString on Day {
    String toJson() {
      return this.toString().split('.').last;
    }
  }
  
  class Saturday {
    String toJson() =&gt; &quot;WOOHOO Saturday&quot;;
  }
  
  main() {
    //works!
    Saturday s=Saturday();
    print(s.toJson());
    print(jsonEncode(s));
    
    Day m = Day.monday;
    print(m.toJson()); //prints 'monday'
    print(m); //prints Day.monday
    print(jsonEncode(m)); // Uncaught Error: Converting object to an encodable object failed: Instance of 'Day'
  }
  </code></pre>
  <p>According to the <a href="https://api.dart.dev/stable/2.15.0/dart-convert/jsonEncode.html" rel="nofollow noreferrer">docs</a>, <code>jsonEncode</code> will look for the <code>toJson()</code> method.</p>
  <p>And the extensions work when called directly on an enum, but somehow jsonEncode isn't finding the toJSON.</p>
  <p><a href="https://stackoverflow.com/questions/29567236/dart-how-to-get-the-value-of-an-enum">Dart How to get the &quot;value&quot; of an enum</a>
  <a href="https://dart.dev/guides/language/extension-methods" rel="nofollow noreferrer">https://dart.dev/guides/language/extension-methods</a></p>
  <p>Any idea if this is a bug or the expected behavior?</p>
  <p>Otherwise, can I use enums and somehow define something to work with jsonEncode?</p>
  <p>Thanks!</p>