title: Pass user built json encoder into Flask's jsonify
body: <p>I want to pass a numpy JSON serializer I wrote into Flask's <code>jsonify</code> function, but I cannot find a way to do this. I cannot use <code>json.dumps</code>, because I have to set the status_code of the Flask response when handling an error message. Is there a way to pass the JSON serializer in as a parameter, similar to using the <code>cls</code> parameter in <code>json.dumps</code> as shown here: <a href="https://stackoverflow.com/questions/27050108/convert-numpy-type-to-python">Convert numpy type to python</a>?
  My code is below; thanks. </p>
  
  <pre><code>import json
  import numpy as np
  from flask import Flask, jsonify
  
  class JSON_Improved(json.JSONEncoder):
      '''
      Used to help jsonify numpy arrays or lists that contain numpy data types.
      '''
      def default(self, obj):
          if isinstance(obj, np.integer):
              return int(obj)
          elif isinstance(obj, np.floating):
              return float(obj)
          elif isinstance(obj, np.ndarray):
              return obj.tolist()
          else:
              return super(MyEncoder, self).default(obj)
  
  app = Flask(__name__)
  @app.errorhandler(ErrorMessage)
  def handle_invalid_usage(error):
      response = jsonify(error.to_dict())
      response.status_code = error.status_code
      return response
  </code></pre>