How can I serialize a MongoDB ObjectId with Marshmallow?

前端 未结 4 1467
你的背包
你的背包 2021-02-14 07:48

I\'m building and API on top of Flask using marshmallow and mongoengine. When I make a call and an ID is supposed to be serialized I receive the following error:



        
4条回答
  •  傲寒
    傲寒 (楼主)
    2021-02-14 08:03

    marshmallow-mongoengine does this:

    Marshmallow-Mongoengine is about bringing together a Mongoengine Document with a Marshmallow Schema.

    import marshmallow_mongoengine as ma
    
    
    class ProcessSchema(ma.ModelSchema):
        class Meta:
            model = Process
    

    It has an ObjectId field that serializes/deserializes ObjectIds.

提交回复
热议问题