title: how to serialize python classes?
body: <p>I have a model class defined as;</p>
  
  <pre><code>class SiteConfig(object):
  
  
      def __init__(self,command,category,frequency,delay):
          self.command=command
          self.category=category
          self.frequency=frequency
          self.delay=delay
  </code></pre>
  
  <p>im calling this model from another class like;</p>
  
  <pre><code>    from flask import Flask,request,jsonify
      import httplib
      from models.SiteConfig import *
  
      app = Flask(__name__)
  
  
      @app.route('/')
      def index():
          return "Endpoint is not configured", 500
  
  
      @app.route('/SitePollingConfiguration',methods=['GET'])
      def SitePollingConfiguration(): 
          response = jsonify(statusCode=httplib.OK, config=BuildSiteConfig())                             
          response.status_code = httplib.OK
  
          return response
  
      def BuildSiteConfig():    
          a= SiteConfig('20c','1',60,60)
          print (a)
          return a
  
  
  if __name__ == '__main__':
      app.run()
  </code></pre>
  
  <p>But im getting <strong>SiteConfig is not JSON serializable</strong> error.</p>
  
  <p>How can i serialize the class object in python?</p>
  
  <p><strong>EDIT</strong>
  i try to use existing flask json encoder;</p>
  
  <p>modified my siteconfig class like;</p>
  
  <pre><code>from flask import Flask, jsonify
  from flask.json import JSONEncoder
  
  class JsonSerializable(object):
      def toJson(self):
          return JSONEncoder.default(self.__dict__)
  
  
  
  class SiteConfig(JsonSerializable):
  
      def __init__(self,command,category,frequency,delay):
          self.command=command
          self.category=category
          self.frequency=frequency
          self.delay=delay
  </code></pre>
  
  <p>And then calling in my main class like;</p>
  
  <pre><code>def ATGSitePollingConfiguration(): 
      response = jsonify(statusCode=httplib.OK, config=BuildATGSiteConfig())                             
      response.status_code = httplib.OK
  
      return response
  
  def BuildATGSiteConfig():    
      a= SiteConfig('20c','1',60,60)
      print (a)
      return a
  </code></pre>
  
  <p>But still  serializable issue. Sorry im new to python;
  can anyone provide simple code sample on how to achieve this?</p>