title: Is it okay to write own magic methods?
body: <p>In my web application I often need to serialize objects as JSON.
  Not all objects are JSON-serializable by default so I am using my own <code>encode_complex</code> method which is passed to the <code>simplejson.dumps</code> as follows: <code>simplejson.dumps(context, default=self.encode_complex)</code></p>
  
  <p>Is it okay to define my own magic method called <code>__json__(self)</code> and then use code similar to the following in <code>encode_complex</code> method?</p>
  
  <pre><code>def encode_complex(self, obj):
      # additional code
  
      # encode using __json__ method
      try:
          return obj.__json__()
      except AttributeError:
          pass
  
      # additional code
  </code></pre>