title: how to serialise a enum property in sqlalchemy using marshmallow
body: <p>this is my model class</p>
  
  <pre><code>class Type(enum.Enum):
      Certified = "certified"
      Non_Certified = "non-certified"
  
  
  class Status(enum.Enum):
      Approved = "Approved"
      Rejected = "Rejected"
      Published = "Published"
      Retired = "Retired"
      Waiting_for_Approval = "Waiting_for_Approval"
  
  
  class DifficultyLevel(enum.Enum):
      Beginner = "Beginner"
      Intermediate = "Intermediate"
      Advanced = "Advanced"
      All = "All"
  
  
  class ActiveStatus(enum.Enum):
      Archive = "archive"
      Restore = "restore"
  
  
  class Course(Base):
      __tablename__ = 'course'
      id = Column(Integer, primary_key=True)
      course_code = Column(String(255))
      duration_in_hours = Column(Integer)
      default_eb_price = Column(Integer)
      modified_by = Column(Integer)
      modified_on = Column(DateTime)
      created_by = Column(Integer)
      created_at = Column(DateTime)
      type = Column(Enum(Type))
      certification_vendor = Column(String(255))
      certification_name = Column(String(255))
      micro_training_sessions = Column(Integer)
      status = Column(Enum(Status))
      title = Column(String(255))
      summary = Column(String(255))
      duration = Column(JSON)
      # Categories =
      delivery_language = Column(String(255))
      course_logo = Column(String(255))
      promo_video = Column(String(255))
      overview = Column(String(255))
      objectives = Column(String(255))
      suggested_attendees = Column(String(255))
      prerequisites = Column(String(255))
      difficulty_level = Column(Enum(DifficultyLevel))
      course_facts = Column(JSON)
      price = Column(String(255))
      list_price = Column(String(255))
      early_bird_price = Column(String(255))
      next_recommended_course = Column(postgresql.ARRAY(Integer))
      specialization_paths = Column(postgresql.ARRAY(Integer))
      active_status = Column(Enum(ActiveStatus))
  
      def __getitem__(self, item):
          return getattr(self, item)
  
      @property
      def serialize(self):
          """Return object data in easily serializeable format"""
          serialized_obj = {}
          for column in self.__table__.columns:
              serialized_obj[column.key] = self[column.key]
          return serialized_obj
  </code></pre>
  
  <p>and this the controller function to edit the change</p>
  
  <pre><code>def update_course_ctrl(obj,course_id):
      args = request.args
      course_schema = CourseSchema()
      if args is not None :
          if args['action'] == "archive":
              course = session.query(Course).filter_by(id=course_id).one()
              course.active_status = 'Archive'
              session.merge(course)
              session.commit()
              dump_data = course_schema.dump(course).data
              return dump_data
              # code to archive course
          if args['action'] == "restore":
              course = session.query(Course).filter_by(id=course_id).one()
              course.active_status = 'Restore'
              session.merge(course)
              session.commit()
              dump_data = course_schema.dump(course).data
              return dump_data
      course = Course(**obj.json)
      session.merge(course)
      session.commit()
      dump_data = course_schema.dump(course).data
      return dump_data
  </code></pre>
  
  <p>this is my code in marshmallow file</p>
  
  <pre><code>from marshmallow_sqlalchemy import ModelSchema
  from sqlalchemy.orm import sessionmaker
  from app.extensions import engine
  from app.course.models import Course, Project, Topic, Resource
  
  
  DBSession = sessionmaker(bind=engine)
  session = DBSession()
  
  
  class CourseSchema(ModelSchema):
      class Meta:
          model = Course
          sqla_session = session
  </code></pre>
  
  <p>while calling this update function I am getting this error
    <strong>TypeError: &lt;ActiveStatus.Archive: 'archive'&gt; is not JSON serializable</strong></p>