[Flask] TypeError: xxxx is not JSON serializable

Jim Icenhower jicenhower at yahoo.com
Wed Nov 11 12:16:00 EST 2015

I'm using Flask Appbuilder which seems to provide it's own REST implemention instead of using Flask-Rest.I have the following class. When I call it's view's api/read function I get the error "TypeError: TXABCD2015 is not JSON serializable". Note that TXABCD2015 is the value returned by the repr() method of the related Event object. It throws this error on all objects related through foreign keys. I really would like the Event repr() value to be included in the json if possible. I would appreciate any advice on what should I do to handle this.Thanks!class CarClass(Model,ModelEnhancer):
    __tablename__ = "CarClass"
    CarClassID = Column(Integer, primary_key=True)
    CarClassKey = Column(String(30), unique=True, nullable=False)
    Marque = Column(String(30), nullable=False)
    Title = Column(String(30), nullable=False)
    Description = Column(Text(1000), nullable=False)
    StartYear = Column(Integer, nullable = True)
    EndYear = Column(Integer, nullable = True)
    EventID = Column(Integer, ForeignKey('event.EventID'), nullable=False)
    Event = relationship('Event')

    def setValues(self, row):
        self.validationMessages = ""
        for key, value in row.iteritems():
            setattr(self, key, value)

    def list_mapped_columns(self):

    def isValid(self):
        validationMessage = ""
        columns = self.required_column_names
        for name in columns:
            print name
            if not getattr(self, name):
                # Add validation message
                self.validationMessages = self.validationMessages + ", " + name + " can not be empty."
        return len(self.validationMessages) == 0

    def __repr__(self):
        return self.CarClassKey Jim
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/flask/attachments/20151111/91d072c7/attachment.html>

More information about the Flask mailing list