title: Making object JSON serializable with regular encoder
body: <p>The regular way of JSON-serializing custom non-serializable objects is to subclass <code>json.JSONEncoder</code> and then pass a custom encoder to <code>json.dumps()</code>.</p>
  <p>It usually looks like this:</p>
  <pre><code>class CustomEncoder(json.JSONEncoder):
      def default(self, obj):
          if isinstance(obj, Foo):
              return obj.to_json()
  
          return json.JSONEncoder.default(self, obj)
  
  print(json.dumps(obj, cls=CustomEncoder))
  </code></pre>
  <p>What I'm trying to do, is to make something serializable with the default encoder. I looked around but couldn't find anything.
  My thought is that there would be some field in which the encoder looks at to determine the json encoding. Something similar to <code>__str__</code>. Perhaps a <code>__json__</code> field.
  Is there something like this in python?</p>
  <p>I want to make one class of a module I'm making to be JSON serializable to everyone that uses the package without them worrying about implementing their own [trivial] custom encoders.</p>