title: Serializing Python Arrow objects for the Flask-Restless API
body: <p>I am currently developing an application with Flask-Restless. When I substituted my SQLAlchemy models' typical DateTime fields with corresponding <a href="http://crsmithdev.com/arrow/" rel="nofollow">arrow</a> fields, all went smoothly. This was due to the help of SQLAlchemy-Utils and its <a href="https://sqlalchemy-utils.readthedocs.org/en/latest/data_types.html?highlight=arrowtype#module-sqlalchemy_utils.types.arrow" rel="nofollow">ArrowType</a> field.</p>
  
  <p>However, after using the API to return a JSON representation of these objects, I received the following error:</p>
  
  <p><strong>TypeError: Arrow [2015-01-05T01:17:48.074707] is not JSON serializable</strong></p>
  
  <p>Where would be the ideal place to modify how the model gets serialized? Do I modify Flask-Restless code to support Arrow objects or write a model method that Flask-Restless can identify and use to retrieve a JSON-compatible object?</p>
  
  <p>I could also write an ugly post-processor function in the meantime but that solution seems like a terrible hack.</p>
  
  <p>Below is an example model with the ArrowType field:</p>
  
  <pre><code>class Novel(db.Model):
      id = db.Column(db.Integer, primary_key=True)
      title = db.Column(db.Unicode, unique=True, nullable=False)
      created_at = db.Column(ArrowType, nullable=False)
  
      def __init__(self, title):
          self.title = title
          self.created_at = arrow.utcnow()
  </code></pre>